一. pipeline介绍
1.1 What is Jenkins Pipeline?
https://www.jenkins.io/doc/book/pipeline/#overview
Jenkins Pipeline (or simply "Pipeline" with a capital "P") is a suite of plugins which supports implementing and integrating continuous delivery pipelines into Jenkins.
解释的咱也没怎么看懂,总结一点就是,jenkins job看着很干净,有利于管理,复制job,你可以把所有拉代码,打包,构建项目工程发布等步骤全部放在一个文件里,这个文件上传到github上,使用很方便,话不多说
1.2 新建一个job
New Item.png
Job.png
1.3 配置build需要的参数,该参数全局可用
image.png
1.4 拉取代码,并指定分支
Pull code.png
1.5 创建子文件夹,设置pipeline读取的Jenkinsfile 路径
该路径是1.4步骤中拉取代码之后的Jenkinsfile的相对路径(如图1.6)
image.png
1.6 pipeline读取的script文件,拉完代码之后,jenkins就会执行该Jenkinsfile中的脚本,继续打包等接下来步骤
1.6.png
1.7 Jenkinsfile文件的脚本,我这里是mac,使用的是shell脚本,主要做的事是:iOS项目编译,archive,重签名
pipeline {
agent {
# 指定node节点
node { label 'Mini-Mac-builder-SH-SSD-M1' }
}
#配置静态变量
environment {
ipa_name="EAM"
APP_VER="3.9.0"
ipa_full_name="${ipa_name}-${BUILD_TYPE}-${APP_VER}.${BUILD_NUMBER}"
}
// 配置超时时间
options { timeout(time: 10, unit: 'MINUTES') }
stages {
#拉取第三方代码
stage('pull common release-2.4-eam3.9 for eam3.9') {
steps {
dir(path: "./OneSource-CommonLib") {
git(
branch: "release-2.4-eam3.9",
credentialsId: "6414ec98-hhhh-hhhh-b800-hhhhhhhhhhhfd",
url : "https://hhhhhhhhhhhhhhhLib.git",
changelog: true,
)
}
}
}
stage('ipa build') {
steps {
sh label: '',
script:
'''
project_name="EAMInventory"
info_plist_name="info"
build_configuration="Release"
fold_name="OneSource-EAM"
fold_sub_name="iOS"
APP_DISPLAY_NAME="OS EAM"
EAM_NAME="EAM"
PROVISIONING_PROFILE_DEV="41c0291a-hhhh-hhhh-87bc-hhhhhhhh"
CERTIFICATE_SHA1_DEV="hhhhhhhhhhhhhhhhD40E855390BA0C72"
DEV_BUNDLEID="com.perkinelmer.ehhhhhhhh"
PRO_CER_NAME="iPhone Distribution: PerkinElmer hhhhhhh, Inc"
PRO_BUNDLEID="com.perkinelmer.hhhhhhhh"
PRO_PROFILE="12329c66-d1c9-hhhh-hhhh-062e478ac7ef"
info_plist_path="${WORKSPACE}/${fold_name}/${fold_sub_name}/${project_name}/${info_plist_name}.plist"
chmod a+rw ${info_plist_path}
archivePlist_path="${WORKSPACE}/${fold_name}/iOS/buildScript"
/usr/libexec/PlistBuddy -c "Set :provisioningProfiles:${DEV_BUNDLEID} ${PROVISIONING_PROFILE_DEV}" "${archivePlist_path}/archive.release.plist"
/usr/libexec/PlistBuddy -c "Set :signingCertificate ${CERTIFICATE_SHA1_DEV}" "${archivePlist_path}/archive.release.plist"
/usr/libexec/PlistBuddy -c "Set CFBundleVersion ${APP_VER}.${BUILD_NUMBER}" "${info_plist_path}"
# xxxx为keychain 密码
security unlock-keychain -p xxxxxxxx
cd ${WORKSPACE}/${fold_name}/ReactNative
#npm install
#export PATH=$PATH:/usr/local/bin
react-native bundle --entry-file index.ios.js --platform ios --bundle-output build/main.jsbundle --sourcemap-output build/main.jsbundle.map --assets-dest build/ --dev false
cd ../iOS
export LANG=zh_CN.UTF-8
#rm -rf podfile.lock
#pod install
xcodebuild -workspace "EAMInventory.xcworkspace" -scheme EAMInventory -archivePath ${WORKSPACE}/build/EAMInventory.xcarchive -configuration "Release" archive
xcodebuild -exportArchive -archivePath ${WORKSPACE}/build/EAMInventory.xcarchive -exportPath ${WORKSPACE}/EAMInventoryIpa -exportOptionsPlist ${archivePlist_path}/archive.release.plist
mkdir -p ${WORKSPACE}/IPA
PROJECT_PATH="${WORKSPACE}/EAMInventoryIpa/${project_name}"
if [ "${BUILD_TYPE}" = "Release" ]
then
PROFILE_PATH="/Users/mini/Library/MobileDevice/Provisioning Profiles/${PRO_PROFILE}.mobileprovision"
open /Users/mini/workspace/iOSAppSigner.app --wait-apps --args -ipa ${PROJECT_PATH}.ipa -ipaout ${PROJECT_PATH}-resigned.ipa -cert "${PRO_CER_NAME}" -profileloc "${PROFILE_PATH}" -newAppId ${PRO_BUNDLEID} -appName "${APP_DISPLAY_NAME}"
mv "${PROJECT_PATH}-resigned.ipa" "${WORKSPACE}/IPA/${EAM_NAME}-${BUILD_TYPE}-${APP_VER}.${BUILD_NUMBER}.ipa"
else
mv "${PROJECT_PATH}.ipa" "${WORKSPACE}/IPA/${EAM_NAME}-${BUILD_TYPE}-${APP_VER}.${BUILD_NUMBER}.ipa"
mkdir /Users/mini/Desktop/crashLog/QAFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
cp -af /Users/mini/workspace/analyseCrash.sh /Users/mini/Desktop/crashLog/QAFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
cp -af ${WORKSPACE}/build/EAMInventory.xcarchive/dSYMs/EAMInventory.app.dSYM /Users/mini/Desktop/crashLog/QAFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
mkdir /Users/mini/Desktop/crashLog/testFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
cp -af /Users/mini/workspace/analyseCrash.sh /Users/mini/Desktop/crashLog/testFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
cp -af ${WORKSPACE}/build/EAMInventory.xcarchive/dSYMs/EAMInventory.app.dSYM /Users/mini/Desktop/crashLog/testFiles/EAMInventory/EAMbeta${APP_VER}.${BUILD_NUMBER}
fi
mkdir -p ${WORKSPACE}/DSYM
cp -af ${WORKSPACE}/build/EAMInventory.xcarchive/dSYMs/EAMInventory.app.dSYM ${WORKSPACE}/DSYM/${APP_VER}.${BUILD_NUMBER}-EAMInventory.app.dSYM
'''
# 修改 build name 和添加下载链接,下载链接为nginx搭建,同局域网可直接下载,速度非常快
buildName "${ipa_full_name}"
buildDescription "<a href='http://165.xx.1xx.xx:8800/mini/workspace/${JOB_NAME}/IPA/${ipa_full_name}.ipa'>download ipa</a>"
}
}
}
}