Jenkins + iOS打包 + 蒲公英上传

Jenkins.jpg

Homebrew

搜索

brew search jenkins

安装

brew install jenkins
启动jenkins: brew services start jenkins
停止jenkins: brew services stop jenkins
重启jenkins: brew services restart jenkins
查看jenkins: ps -ef | grep jenkins

修改默认端口的方法:打开文件 vi /usr/local/opt/jenkins/homebrew.mxcl.jenkins.plist修改默认端口号httpPort

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>homebrew.mxcl.jenkins</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/opt/openjdk@11/bin/java</string>
                <string>-Dmail.smtp.starttls.enable=true</string>
                <string>-jar</string>
                <string>/usr/local/opt/jenkins/libexec/jenkins.war</string>
                <string>--httpListenAddress=127.0.0.1</string>
                <string>--httpPort=8081</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
</dict>
</plist>
~          

局域网访问需要修改httpListenAddress的值127.0.0.1修改为0.0.0.0

卸载jenkins:  brew uninstall jenkins

启动Jenkins

  1. brew services start jenkins

  2. 打开网址:localhost:8081

初始化.jpeg
  1. 红色路径是Jenkins启动密码路径
    进入访达 按住 command + shift + g 将路径粘贴进入打开文件initialAdminPassword复制密码填写到web位置

  2. 安装默认插件


    1.jpeg

    2.jpeg

    3.jpeg
  3. 设置用户名与密码


    用户设置.jpeg

此时基本完成Jenkins环境安装与基础配置

构建iOS包

1 安装插件

  1. 选择系统管理


    首页.png
  2. 进入插件管理


    系统配置.png
  3. 添加所需插件

  1. Xcode integration
  2. GitLab Plugin
  3. Gitlab Hook Plugin
  4. Keychains and Provisioning Profiles Management
1.png

安装完成后重启Jenkins,命令行 brew services restart jenkinshttp://localhost:8080/restart
个人简单来直接在网址后面修改

2 创建项目

1.png

参数配置

1 git地址配置

2.png
2.2.png

2 项目shell脚本打包

3.png
cocoapods 脚本
3.1.png

脚本命令

#bin/bsah - l

export LANG=en_US.UTF-8

export LANGUAGE=en_US.UTF-8

export LC_ALL=en_US.UTF-8

cd ${WORKSPACE}/leimingBusiness

/usr/local/bin/pod install --verbose --no-repo-update
build工程
3.2.png
#!/bin/bash

#注意:脚本目录和WorkSpace目录在同一个目录
#工程名字(Target名字)
Project_Name="leimingBusiness"

Project_Path="${WORKSPACE}/leimingBusiness/"
#workspace的名字
Workspace_Name="leimingBusiness"
#配置环境,Release或者Debug,默认release
Configuration="Debug"

EnterpriseExportOptionsPlist="$Project_Path"EnterpriseExportOptionsPlist.plist

EnterpriseExportOptionsPlist=${EnterpriseExportOptionsPlist}

echo " ---- clear --- "
xcodebuild -workspace ${Project_Path}"$Workspace_Name.xcworkspace" -scheme "${Project_Name}"  -configuration ${Configuration} clean

echo " ---- archive ---- "
xcodebuild -workspace ${Project_Path}$Workspace_Name.xcworkspace -scheme $Project_Name -configuration $Configuration -archivePath ${Project_Path}build/$Project_Name-enterprise.xcarchive archive build 

xcodebuild  -exportArchive -archivePath ${Project_Path}build/$Project_Name-enterprise.xcarchive -exportOptionsPlist ${EnterpriseExportOptionsPlist} -exportPath $HOME/Desktop/MyWorkPlace/自动化打包IPAs/$Project_Name-enterprise

保存配置

上传蒲公英操作

构建后操作

添加两个插件
Upload to pgyer with apiV1
Set build description

如果没有返回Jenkins插件管理下载

// 蒲公英插件
Upload to pgyer
// 描述插件
description setter
1.png

填写内容


2.png

HTML 文本标签

<a href="${appBuildURL}"><img src="${appQRCodeURL}" width="118" height="118"/></a>

保存后 设置Jenkins HTML格式默认Jenkins 回显方式text
进入 系统管理 -> 全局安全配置 -> 标记格式器

3.png

发送消息到企业微信

企业微信群设置添加机器人

Jenkins安装post build task模板插件

image.png

sh脚本

curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxx' \
   -H 'Content-Type: application/json' \
   -d '
   {
    "msgtype": "news",
    "news": {
       "articles" : [
           {
               "title" : "iOS",
               "description" : "测试环境",
               "url" : "'${appBuildURL}'",
               "picurl" : "'${appQRCodeURL}'"
           }
        ]
    }
}'

参考

Jenkins一:iOS自动打包完整实践
iOS持续集成—Jenkins(最新最全)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。