美文网首页
一次 Jenkins 入坑记录

一次 Jenkins 入坑记录

作者: AppleTTT | 来源:发表于2018-05-28 14:47 被阅读69次

最近在使用 Jenkins 打包的时候,上传到 fir 上的包,没有 dSYM 符号表信息,导致虽然使用了 bugly,但是没有符号表还是没法定位到错误的地方,于是开始研究了下 Jenkins 的配置。

我是在同事已经搭建好的 Jenkins 服务器上新建任务的,之前的同事是直接用的 Xcode integration 来做 buildexport 操作的,我看了下,没有找到具体 export 选项,可能是我没有找到,不能配置的话,默认的 exportOptions 里面的 stripSwiftSymbolsYES,导致 ipa 里面没有符号表;于是改用了直接用脚本来打包,步骤如下:

新建任务

输入一个任务名称 -> 构建一个自由风格的软件项目

任务执行步骤

1.描述(描述该任务的大致内容)
2.HTML5 Notification Configuration

丢弃旧的构建


(参数化构建过程.png)

参数化构建过程


参数化构建过程.png

3.源码管理

源码管理.png

4.构建触发器,我没有做这一块,因为我们项目都是需要打包的时候,再去 jenkins 上去打包。

5.构建环境:这一块主要是用来管理证书相关的东西;我就设置了如下两项:

Keychains and Code Signing Identities

Keychains and Code Signing Identities.png

Mobile Provisioning Profiles


Mobile Provisioning Profiles.png

6.构建:构建的具体步骤,前面都是算是准备工作,接下来就是如何获取源码,如何打包,如何导出以及导出后的步骤:

  • 执行 shell -> 拉取最新的代码:
buildPlist="${WORKSPACE}/XXX/XXXInfo.plist"
# 拿到最新的 build 号,这个会在每次打包的时候去做 +1 操作,我所有文件都是放在 Jenkins 目录下,大家也可以放在自己选定的目录下
buildNumberFile="${JENKINS_HOME}/.ios_build_version.txt"
    
APPBuildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $buildPlist)
    
APPBuildNumber=$(cat $buildNumberFile)
    
APPBuildNumber=$((APPBuildNumber + 1))
    
echo "$APPBuildVersion-build(${APPBuildNumber})-${GIT_LOCAL_BRANCH}" > version.txt
    
# save APPBuildNumber to Jenkins for next build
echo $APPBuildNumber > $buildNumberFile
    
# Set the version numbers in the buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $APPBuildNumber" $buildPlist
    
git config --global user.name "Jenkins"
git config --global user.email jenkins@XXX.com
git fetch
git branch --set-upstream-to=remotes/${GIT_BRANCH} ${GIT_LOCAL_BRANCH}
git pull
git add .
git commit -m "[jenkins] set build numbers: ${APPBuildNumber}"
    git push
  • 新增构建步骤 -> upload build name,勾选 read from file

  • 执行 shell -> 拉取最新的 pod 依赖

rm -rf Pods
pod install
  • 执行 shell -> build & export
PROJECT_NAME="project_name"
# 环境 -> Debug or Release
CONFIGURATION="Debug"
# 要 build 的 scheme
CURRENT_SHEME="your_scheme"
# 签名
SigningIdentity="iOS Developer"

# build 的 plist
buildPlist="${WORKSPACE}/XXX/XXXInfo.plist"
buildNumberFile="${JENKINS_HOME}/.ios_build_version.txt"
BOUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $buildPlist)
# export 选项
ExportOptionsPlistPath="${WORKSPACE}/ExportOptions/ExportOptions.plist"


# clean
echo "================= Clean一下 ================="
xcodebuild clean -workspace ${PROJECT_NAME}.xcworkspace \
                 -scheme ${CURRENT_SHEME} \
                 -configuration ${CONFIGURATION}

#-alltargets
echo "================= Clean一下 Over ================="
s
# archive
echo "============== archive =================="
xcodebuild archive  -workspace ${PROJECT_NAME}.xcworkspace \
                    -scheme ${CURRENT_SHEME} \
                    -configuration ${CONFIGURATION} \
                    CFBundleVersion=${BOUNDLE_VERSION} \
                    -destination generic/platform=ios \
                    -archivePath build/${CURRENT_SHEME}.xcarchive

# export ipa
echo "+++++++++++++++++ exportArchive +++++++++++++++++"
xcodebuild -exportArchive -archivePath build/${CURRENT_SHEME}.xcarchive \
                          -exportPath build/${CURRENT_SHEME}\
                          -destination generic/platform=ios\
                          -exportOptionsPlist ${ExportOptionsPlistPath}\
                          -allowProvisioningUpdates
  • 执行 shell -> 将打包好的 ipa 上传到 fir 或者是 App store
token="your_fir_token"
fir p $WORKSPACE/build/XXX/XXX.ipa -T ${token} -c "$release_note"
altool --validate-app -f "${WORKSPACE}/build/XXX/XXX.ipa" -u "your_apple_ID" -p "your_apple_ID_password" -t ios --output-format xml
altool --upload-app -f "${WORKSPACE}/build/XXX/XXX.ipa" -u "your_apple_ID" -p "your_apple_ID_password" -t ios --output-format xml

以上就是构建的设置,当然还有很多操作就是下载插件或证书管理等,很多 blog 都说了很多,我就不说了

参考

霜神:手把手教你利用Jenkins持续集成iOS项目
xcodebuild官方文档
xcrun官方文档
详解Shell脚本实现iOS自动化编译打包提交
使用Jenkins实现持续集成

相关文章

网友评论

      本文标题:一次 Jenkins 入坑记录

      本文链接:https://www.haomeiwen.com/subject/volgjftx.html