Jenkins一键发布 ipa 到蒲公英

什么是 Jenkins

Jenkins是一个持续集成工具,它可以在设定的某个时间点(或者代码有更新等情况)自动去构建安装包,同时可以将安装包上传到第三方平台,比如:Bugly、蒲公英,这样测试人员可以通过微信、QQ扫一扫直接安装(Bugly的链接可以直接在微信内打开,这是我选择它的原因)。

附上下载地址 :Jenkins

建议下载 <code>.war</code>文件 配合<code>Tomcat</code>环境使用.

直接下载了<code>.war</code>文件,这个文件是直接放在<code>Tomcat</code>下<code>webapps</code>目录下.

优点:它的权限就是当前用户.

开始安装Tomcat

附上下载地址 :Tomcat

把下载好的<code> Tomcat </code>文件夹 放到你想放的目录

然后把 <code>.war</code> 文件放入 <code>Tomcat</code>文件夹下的 <code>webapps</code> 目录下

运行Jenkins

命令行进入<code>Tomcat</code>安装目录.

<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
</pre>
可能会报 <code>-bash: /Users/ooops/apache-tomcat-7.0.75/bin/startup.sh: Permission denied</code>错误,这是因为对该文件没有执行权限造成的.

执行如下命令:
<pre>
chmod +x *.sh
</pre>
然后执行
<pre>
sh startup.sh
</pre>
打开浏览器输入 localhost:8080 看到 <code>Tomcat</code>启动页面,表示<code>Tomcat</code>安装成功

《Jenkins一键发布 ipa 到蒲公英》

<code>盗来的图</code>

进入<code>Tomcat</code>目录下 <code>conf</code>打开 <code>tomcat-users.xml</code>文件,在文件根节点结束之前添加如下配置.

《Jenkins一键发布 ipa 到蒲公英》

使用如下命令重启Tomcat
<pre>
cd /Users/ooops/apache-tomcat-7.0.75/bin
sh shutdown.sh
sh startup.sh
</pre>
再次登录<code>Tomcat</code>,选择下图<code>Jenkins</code>

《Jenkins一键发布 ipa 到蒲公英》

输入如下命令查看Jenkins初始密码
<pre>
open /Users/ooops/.jenkins/secrets/initialAdminPassword
</pre>

《Jenkins一键发布 ipa 到蒲公英》

粘贴初始密码,点击继续,等待片刻

《Jenkins一键发布 ipa 到蒲公英》

选择<code>Install suggested plugins </code>

推荐的插件安装完毕,还有我们自己需要的插件安装.
首先进入插件管理器界面

《Jenkins一键发布 ipa 到蒲公英》

然后在可选插件中搜索我们需要的插件,进行安装.

《Jenkins一键发布 ipa 到蒲公英》

GIT 环境下我们需要安装的插件有 三 个.操作步骤参见上图.

  • <code>Gitlab Hook Plugin </code> 因为我们用的是GitLab来管理源代码,Jenkins本身并没有自带GitLab插件
  • <code>Xcode</code> Xcode环境插件.
  • <code>Keychains and Provisioning Profiles Management</code> 钥匙串和证书配置.

配置GIT

私钥文件位置 家目录下的 <code>.ssh</code> 文件夹下

配置<code>GIT</code> 私钥

《Jenkins一键发布 ipa 到蒲公英》

《Jenkins一键发布 ipa 到蒲公英》

点击OK完成GIT私钥配置.

钥匙串和证书配置

《Jenkins一键发布 ipa 到蒲公英》

钥匙串文件路径 : <code> /Users/用户名(your user name)/Library/Keychains/login.keychain</code>

上传<code>钥匙串 keychain </code>和 <code>证书描述文件 Provisioning Profile</code>
上传之后的要是串和证书描述文件会被<code>Jenkins</code>保存在<code>/Users/改成你的(your user name)/.jenkins/kpp_upload</code>目录下

《Jenkins一键发布 ipa 到蒲公英》

配置对应的钥匙串中的<code>开发(调试)</code> <code>生产(发布)</code> 证书

首先打开钥匙串,进行如下操作.

《Jenkins一键发布 ipa 到蒲公英》

其次 获取证书的常用名称

《Jenkins一键发布 ipa 到蒲公英》

我们将证书的常用名称点入 钥匙串的配置中,具体配置参考下图

《Jenkins一键发布 ipa 到蒲公英》

上图目录配置有问题,改为/Users/改成你的(your user name)/.jenkins/kpp_upload.偷个懒 不补图了.

点击确定完成配置.

系统全局配置

Jenkins 主页 -> 系统管理 -> 系统设置 -> 全局属性 -> 勾选<code>Keychains and Provisioning Profiles Management</code> 填入上传到 Jenkins 的证书和描述文件目录
<code>/Users/ooops/.jenkins/kpp_upload</code>

下面开始构建通用项目配置.

《Jenkins一键发布 ipa 到蒲公英》

参数可根据自己的实际需求更改

点击确定

General 参数

《Jenkins一键发布 ipa 到蒲公英》

源码管理 参数

《Jenkins一键发布 ipa 到蒲公英》

构建触发器设置

这里是设置自动化测试的地方。
涉及的内容很多,
暂时我也没有深入研究,这里暂时先不设置。
有自动化测试需求的可以 研究研究这里的设置。

不过这里两个配置还是需要是设置的

<code>Poll SCM (poll source code management)</code> 轮询源码管理

需要设置源码的路径才能起到轮询的效果。

一般设置为类似结果: 0/5 每5分钟轮询一次

<code>Build periodically</code> (定时构建)

一般设置为类似: 00 20 * 每天 20点执行定时构建

格式如下 (具体可以参考后面的小问号??) 嘿嘿

分钟(0-59) 小时(0-23) 日期(1-31) 月(1-12) 周几(0-7,0和7都是周日)

设置之后文本输入域下面会有你填写格式的翻译.

参数配置参考:

http://blog.csdn.net/xueyingqi/article/details/53216506

http://blog.csdn.net/yezicjj/article/details/52763700

《Jenkins一键发布 ipa 到蒲公英》

构建环境 参数

参考下图设置

《Jenkins一键发布 ipa 到蒲公英》

如果这里没有可选择的钥匙串和描述文件,请参考 钥匙串和证书配置 中关于钥匙串的配置.

构建 设置

《Jenkins一键发布 ipa 到蒲公英》

<pre>

工程名

APP_NAME=”你的项目名称”

证书

CODE_SIGN_DISTRIBUTION=”iPhone Developer: XXXXXXX”

CODE_SIGN_DISTRIBUTION=”iPhone Distribution: XXXXXXXXXX”

info.plist路径

project_infoplist_path=”./${APP_NAME}/Info.plist”

取版本号

bundleShortVersion=$(/usr/libexec/PlistBuddy -c “print CFBundleShortVersionString” “${project_infoplist_path}”)

取build值

bundleVersion=$(/usr/libexec/PlistBuddy -c “print CFBundleVersion” “${project_infoplist_path}”)

DATE=”$(date +%Y%m%d)”
IPANAME=”${APP_NAME}V${bundleShortVersion}${DATE}.ipa”

IPANAME=”${APP_NAME}.ipa”

要上传的ipa文件路径

IPA_PATH=”$HOME/${IPANAME}”
echo ${IPA_PATH}
echo “${IPA_PATH}”>> text.txt

下面2行是没有Cocopods的用法

echo “=================clean=================”
xcodebuild -target “${APP_NAME}” -configuration ‘Release’ clean

echo “+++++++++++++++++build+++++++++++++++++”
xcodebuild -target “${APP_NAME}” -sdk iphoneos -configuration ‘Release’ CODE_SIGN_IDENTITY=”${CODE_SIGN_DISTRIBUTION}” SYMROOT=’$(PWD)’

//下面2行是集成有Cocopods的用法

echo “=================clean=================”

xcodebuild -workspace “${APP_NAME}.xcworkspace” -scheme “${APP_NAME}” -configuration ‘Release’ clean

echo “+++++++++++++++++build+++++++++++++++++”

xcodebuild -workspace “${APP_NAME}.xcworkspace” -scheme “${APP_NAME}” -sdk iphoneos -configuration ‘Release’ CODE_SIGN_IDENTITY=”${CODE_SIGN_DISTRIBUTION}” SYMROOT=’$(PWD)’

xcrun -sdk iphoneos PackageApplication “./Release-iphoneos/${APP_NAME}.app” -o ~/”${IPANAME}”

蒲公英上的User Key

uKey=”9b0aa78a32a……4e1ca68bdbf”

蒲公英上的API Key

apiKey=”ac75fcf38…..7b9f19f2e4b23″

要上传的ipa文件路径

IPA_PATH=$(cat text.txt)

rm -rf text.txt

执行上传至蒲公英的命令

echo “++++++++++++++upload+++++++++++++”
curl -F “file=@${IPA_PATH}” -F “uKey=${uKey}” -F “_api_key=${apiKey}” http://www.pgyer.com/apiv1/app/upload
</pre>

构建项目

《Jenkins一键发布 ipa 到蒲公英》

以下是一次成功构建的输出信息

<pre>
Started by user ooops
Building in workspace /Users/ooops/.jenkins/workspace/test

git rev-parse –is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository //拉取GIT仓库
git config remote.origin.url git@github.com:xxxxx/jenkinsTest.git # timeout=10
Fetching upstream changes from git@github.com:xxxxx/jenkinsTest.git
git –version # timeout=10
git fetch –tags –progress git@github.com:xxxxx/jenkinsTest.git +refs/heads/:refs/remotes/origin/
git rev-parse refs/remotes/origin/master^{commit} # timeout=10
git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 1f023f0132273ddc4d3d98a8283e3a15bbe254aa (refs/remotes/origin/master)
git config core.sparsecheckout # timeout=10
git checkout -f 1f023f0132273ddc4d3d98a8283e3a15bbe254aa
git rev-list 1f023f0132273ddc4d3d98a8283e3a15bbe254aa # timeout=10
[test] $ /bin/sh -xe /Users/ooops/apache-tomcat-7.0.75/temp/hudson6997647762219224773.sh

  • APP_NAME=jenkinsTest
  • CODE_SIGN_DISTRIBUTION=’iPhone Developer: xxxxx’
  • project_infoplist_path=./jenkinsTest/Info.plist
    ++ /usr/libexec/PlistBuddy -c ‘print CFBundleShortVersionString’ ./jenkinsTest/Info.plist
  • bundleShortVersion=1.0
    ++ /usr/libexec/PlistBuddy -c ‘print CFBundleVersion’ ./jenkinsTest/Info.plist
  • bundleVersion=1
    ++ date +%Y%m%d
  • DATE=20170312
  • IPANAME=jenkinsTest_V1.0_20170312.ipa
  • IPA_PATH=/Users/ooops/jenkinsTest_V1.0_20170312.ipa
  • echo /Users/ooops/jenkinsTest_V1.0_20170312.ipa
    /Users/ooops/jenkinsTest_V1.0_20170312.ipa
  • echo /Users/ooops/jenkinsTest_V1.0_20170312.ipa
  • echo =================clean=================
    =================clean=================
  • xcodebuild -target jenkinsTest -configuration Release clean
    2017-03-12 12:56:15.278 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:15.279 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/HOStringSense.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:15.280 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ESJsonFormat.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:15.280 xcodebuild[12363:1935879] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxD8-C509-4xB-8xx5-84xxxxxxx701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Auto-Importer.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    === CLEAN TARGET jenkinsTest OF PROJECT jenkinsTest WITH CONFIGURATION Release ===

Check dependencies

Create product structure
/bin/mkdir -p /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app

Clean.Remove clean build/jenkinsTest.build/Release-iphoneos/jenkinsTest.build
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/jenkinsTest.build/Release-iphoneos/jenkinsTest.build

Clean.Remove clean build/Release-iphoneos/jenkinsTest.app
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app

Clean.Remove clean build/Release-iphoneos/jenkinsTest.app.dSYM
builtin-rm -rf /Users/ooops/.jenkins/workspace/test/build/Release-iphoneos/jenkinsTest.app.dSYM

** CLEAN SUCCEEDED **

  • echo +++++++++++++++++build+++++++++++++++++
    +++++++++++++++++build+++++++++++++++++
  • xcodebuild -target jenkinsTest -sdk iphoneos -configuration Release ‘CODE_SIGN_IDENTITY=iPhone Developer: xxxxxxxxxxxxxxxx’ ‘SYMROOT=$(PWD)’
    2017-03-12 12:56:16.118 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxx8-C509-4xxB-8B55-84AxxxxxE701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:16.119 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DAxxxxD8-C509-4D8B-8xxxx-84Axxxx01 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/HOStringSense.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:16.119 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID DA4xxx8-C509-4Dxx-8xx5-84AxxxE701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/ESJsonFormat.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    2017-03-12 12:56:16.120 xcodebuild[12376:1936105] [MT] PluginLoading: Required plug-in compatibility UUID Dxxxx8-C509-xx-8B55-84xxxxxAE701 for plug-in at path ‘~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Auto-Importer.xcplugin’ not present in DVTPlugInCompatibilityUUIDs
    Build settings from command line:
    CODE_SIGN_IDENTITY = iPhone Developer: qiang zhang (36XGYU49EQ)
    SDKROOT = iphoneos10.1
    SYMROOT = $(PWD)

=== BUILD TARGET jenkinsTest OF PROJECT jenkinsTest WITH CONFIGURATION Release ===

Check dependencies

Validate Release-iphoneos/jenkinsTest.app
cd /Users/ooops/.jenkins/workspace/test
export PATH=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/ooops/.rvm/gems/ruby-2.2.2/bin:/Users/ooops/.rvm/gems/ruby-2.2.2@global/bin:/Users/ooops/.rvm/rubies/ruby-2.2.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ooops/.rvm/bin:/Users/ooops/.rvm/bin”
export PRODUCT_TYPE=com.apple.product-type.application
builtin-validationUtility /Users/ooops/.jenkins/workspace/test/Release-iphoneos/jenkinsTest.app -validate-for-store

** BUILD SUCCEEDED **

  • xcrun -sdk iphoneos PackageApplication ./Release-iphoneos/jenkinsTest.app -o /Users/ooops/jenkinsTest_V1.0_20170312.ipa

warning: PackageApplication is deprecated, use xcodebuild -exportArchive instead.

//这里是上传蒲公英的配置.

  • uKey=9b0aa78a32……..64e1ca68bdbf

  • apiKey=ac75fcf3……….a47b9f19f2e4b23
    ++ cat text.txt

  • IPA_PATH=/Users/ooops/jenkinsTest_V1.0_20170312.ipa

  • rm -rf text.txt

  • echo ++++++++++++++upload+++++++++++++
    ++++++++++++++upload+++++++++++++

  • curl -F file=@/Users/ooops/jenkinsTest_V1.0_20170312.ipa -F uKey=9b0aa78a32…af26..4e1ca68bdbf -F _api_key=ac75fcf38f2………19f2e4b23 http://www.pgyer.com/apiv1/app/upload
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed

    0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0
    0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0
    100 32843 0 0 100 32843 0 21213 0:00:01 0:00:01 –:–:– 21202
    100 32843 0 0 100 32843 0 12862 0:00:02 0:00:02 –:–:– 12859
    100 33438 100 595 100 32843 220 12149 0:00:02 0:00:02 –:–:– 12146
    {“code”:0,”message”:””,”data”:{“appKey”:”dd580f5………..0305ac671″,”userKey”:”9b0aa78a………e1ca68bdbf”,”appType”:”1″,”appIsLastest”:”1″,”appFileSize”:”32368″,”appName”:”jenkinsTest”,”appVersion”:”1.0″,”appVersionNo”:”1″,”appBuildVersion”:”2″,”appIdentifier”:”com.ooops.pull”,”appIcon”:””,”appDescription”:””,”appUpdateDescription”:””,”appScreenshots”:””,”appShortcutUrl”:”nZwg”,”appCreated”:”2017-03-12 12:56:18″,”appUpdated”:”2017-03-12 12:56:18″,”appQRCodeURL”:”http://static.pgyer.com/app/qrcodeHistory/ea895709d0e57a4a8e4c8f57811838b2ce985322a94f9443e64a0937c6d29e30“}}Finished: SUCCESS
    </pre>

上传到蒲公英

《Jenkins一键发布 ipa 到蒲公英》

END

    原文作者:强哥来简述
    原文地址: https://www.jianshu.com/p/296a8dfaea63
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞