pipeline {
agent {
label 'MacOS'
}
parameters {
choice choices: ['AdHoc', 'AppStore', 'Development'], description: '请选择对应功能:1-正式本地安装 2-苹果开发者包 3-测试版本', name: 'FUNCTION'
// extendedChoice description: '请选择构建环境', multiSelectDelimiter: ',', name: 'envs', propertyFile: '/data/jksconf/jkslist', propertyKey: 'envs', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_SINGLE_SELECT', visibleItemCount: 5
gitParameter branch: '', branchFilter: '.*', defaultValue: 'origin/master', description: '代码分支', name: 'project', quickFilterEnabled: false, selectedValue: 'NONE', sortMode: 'NONE', tagFilter: '*', type: 'PT_BRANCH_TAG'
}
stages {
stage('Checkout Code') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '${project}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'xxxxxxxxxxxxxxxxxxxxxxx', url: 'ssh://git@xxxxxxxxxxxxx']]])
}
}
stage('编译ipa包'){
steps {
sh label: '', script: '''
is_workspace="true"
scheme_name="testdemo"
info_plist_name="Info"
build_configuration="Release"
ipa_name="$scheme_name"
export_path=~/IPA/${ipa_name}
test -d ${export_path} || mkdir -p ${export_path}
rm -rf ${export_path}/*
export_archive_path="${export_path}/${ipa_name}.xcarchive"
export_ipa_path="${export_path}"
ExportOptionsPlistPath="/Users/fengwan/Desktop/AutoPacking/${FUNCTION}ExportOptions.plist"
project_name=`find . -name *.xcodeproj | awk -F "[/.]" '{print $(NF-1)}'`
info_plist_path="${project_name}/${info_plist_name}.plist"
bundle_version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist_path`
bundle_build_version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist_path`
bundle_identifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist_path`
#苹果电脑的账号密码
security unlock-keychain -p 123456
if $is_workspace ; then
# 编译前清理工程
xcodebuild clean -workspace ${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -workspace ${project_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
else
# 编译前清理工程
xcodebuild clean -project ${project_name}.xcodeproj \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -project ${project_name}.xcodeproj \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
fi
xcodebuild -exportArchive \
-archivePath ${export_archive_path} \
-exportPath ${export_ipa_path} \
-exportOptionsPlist ${ExportOptionsPlistPath}
cd ${export_path}
qrcode=$(curl -s -k -F "file=@${ipa_name}.ipa" http://app.xxxxx.com/upload.php)
echo ${qrcode}>qrcode
'''
script {
QRCODE = sh(returnStdout: true, script: 'cd ~/IPA/xxxxxx && cat qrcode')
VERSION = sh(returnStdout: true, script: "echo $project")
FUNC = sh(returnStdout: true, script: "echo ${FUNCTION}")
buildDescription "构建分支:${VERSION}-${FUNC}<br><img height='200' width='200' src=${QRCODE}></img>"
}
}
}
}
post {
always {
echo 'One way or another, I have finished'
deleteDir() /* clean up our workspace */
}
success {
// buildDescription("<img src=${qrcode}></img>")
echo 'I succeeeded!'
}
unstable {
echo 'I am unstable :/'
}
failure {
echo 'I failed :('
}
changed {
echo 'Things were different before...'
}
}
}
以上这些是不够的,需要在苹果机器上安装下载证书以及jenkins连接MacOS slave node
来源:oschina
链接:https://my.oschina.net/u/4301845/blog/4946072