如何在Mac上新建Jenkins agent节点进行iOS打包(二)

来源:互联网 发布:擦除上网痕迹软件 编辑:程序博客网 时间:2024/06/02 03:14

IOS打包环境配置
相关工具
以下是在agent中需要安装的工具,把这些工具以及环境变量配置完备,agent才能进行IOS打包工作
● git
● xcode
● cocospods(可选)
● fastlane(可选)

证书安装及keychain配置
另外需要额外注意的是,IOS打包时,需要安装项目对应开发者的证书到agent的mac机器上,并且将开发者的apple账号配置到keychain中,并且保存在System种类中,这样我们的jenkins才能够进行打包操作,否则将打包失败。
证书也需要放在”系统”钥匙串中

jenkins让agent工作时,会启动一个non-interactive的shell,所以诸如配置在~/.zshrc,/etc/zshrc中的环境变量都不会加载。
此时能被加载的是/etc/zshenv,~/.zshenv,这里我们使用的是~/.zshenv
环境变量配置
图1
IOS项目相关脚本
以下便是IOS项目用到的jenkinsfile脚本

pipeline {    agent none    environment {        revision = ""    }    stages {        stage('test') {            agent {                label 'agent-name'            }            steps {                script {                    revision = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()                    echo revision                }                sh 'fastlane test'                echo 'build dev'            }        }        stage('build dev') {            agent {                label 'agent-name'            }            steps {                sh 'fastlane dev'                echo 'build dev'            }        }        stage('build qa?') {            agent none            steps {                script {                    input message: 'build qa version?'                }            }        }        stage('build qa') {            agent {                label 'agent-name'            }            steps {                sh 'git checkout -f ' + revision                sh 'fastlane qa'                echo 'build qa'            }        }        stage('build uat?') {            agent none            steps {                script {                    input message: 'build uat version?'                }            }        }        stage('build uat') {            agent {                label 'agent-name'            }            steps {                sh 'git checkout -f ' + revision                sh 'fastlane uat'                echo 'build uat'            }        }        stage('build prod?') {            agent none            steps {                script {                    input message: 'build prod version?'                }            }        }        stage('build prod') {            agent {                label 'agent-name'            }            steps {                sh 'git checkout -f ' + revision                sh 'fastlane prod'                echo 'build prod'            }        }    }}

以下便是IOS项目用到的fastlane脚本

fastlane_version "2.45.0"default_platform :iosplatform :ios do  before_all do    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."    cocoapods  end  desc "Runs all the tests"  lane :test do    scan(scheme:'iOS-Startup')  end desc 'fastlane dev'   lane :dev do   time = Time.new   ft   = time.strftime(“%Y%m%d_%H%M%S”)   sigh(    output_path: "/tmp",    skip_certificate_verification: true,    app_identifier: "com.xx.xxx"   )   gym( scheme: 'iOS-Startup',        export_method: "enterprise",        clean: true,        output_directory: "./build",         output_name: “#{ft}.ipa")   end  desc 'fastlane qa'   lane :qa do   time = Time.new   ft   = time.strftime(“%Y%m%d_%H%M%S”)   sigh(    output_path: "/tmp",    skip_certificate_verification: true,    app_identifier: "com.xx.xxx"   )   gym( scheme: 'iOS-Startup',        export_method: "enterprise",        clean: true,        output_directory: "./build",         output_name: “#{ft}.ipa")   end  desc 'fastlane uat'   lane :uat do   time = Time.new   ft   = time.strftime(“%Y%m%d_%H%M%S”)   sigh(    output_path: "/tmp",    skip_certificate_verification: true,    app_identifier: "com.xx.xxx"   )   gym( scheme: 'iOS-Startup',        export_method: "enterprise",        clean: true,        output_directory: "./build",         output_name: “#{ft}.ipa")   end  desc 'fastlane prod'   lane :prod do   time = Time.new   ft   = time.strftime(“%Y%m%d_%H%M%S”)   sigh(    output_path: "/tmp",    skip_certificate_verification: true,    app_identifier: "com.xx.xxx"   )   gym( scheme: 'iOS-Startup',        export_method: "enterprise",        clean: true,        output_directory: "./build",         output_name: “#{ft}.ipa")   end  # You can define as many lanes as you want  after_all do |lane|    # This block is called, only if the executed lane was successful    # slack(    #   message: "Successfully deployed new App Update."    # )  end  error do |lane, exception|    # slack(    #   message: exception.message,    #   success: false    # )  endend
原创粉丝点击