Jenkins pipeline自動打包iOS

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章