iOS Jenkins流水线+fastlane

选择多分支流水线创建

image.png

配置git项目仓库地址

image.png

设置脚本路径

image.png

点击 立刻扫描 多分支流水线, 会获取到所有的有改动的分支

image.png

Jenkinsfile脚本文件

#!/usr/bin/env groovy

pipeline {
    options {
        timeout(time: 3600, unit: 'SECONDS')   // timeout on whole pipeline job
        buildDiscarder(logRotator(artifactDaysToKeepStr: '1',numToKeepStr: "5000"))
    }

    agent {
        label 'ios-china'
    }

//    agent any

    stages {
        //auto cancel redundant builds
        stage('Stop Previous Running Build') {
//            when {
//                    branch 'Dev4'
//            }
            steps {
                echo '自动取消冗余构建'
                milestone label: '', ordinal: Integer.parseInt(env.BUILD_ID) - 1
                milestone label: '', ordinal: Integer.parseInt(env.BUILD_ID)
            }
        }
    
        //Build
        stage('Build') {
            parallel {
                stage('build-uat') {
                    when {
                        anyOf {
                            branch 'Test'
                        }
                    }
                    steps {
                        retry(count: 2) {
//                            sh 'gem install fastlane'
                            sh "cd 目录/ && fastlane脚本"
                        }
                    }
                    /*    post {
                            always {
                                archiveArtifacts artifacts: 'build/ipa/',
                                        fingerprint: false
                            }
                        } */
                }
                
                stage('build-pre') {
                    when {
                        anyOf {
                            branch 'Uat'
                        }
                    }
                    steps {
                        retry(count: 2) {
//                            sh 'gem install fastlane'
                            sh "cd 目录/ && fastlane脚本"
                        }
                    }
                }
                                
                
                stage('build-prod') {
                    when {
                        anyOf {
                            branch 'Pro'
                        }
                    }
                    steps {
                        retry(count: 2) {
//                            sh 'gem install fastlane'
                            sh "cd 目录/ && fastlane脚本"
                        }
                    }
                }
                
            }
        }
    }

    post {
        success {
            cleanWs()
        }
    }
}


fastlane文件在上篇文章

在对应的的分支提交代码,会进入Jenkinsfile对应的环境执行不同环境的fastlane脚本,最后就ok啦编译成功!

image.png

你可能感兴趣的:(iOS Jenkins流水线+fastlane)