Jenkinsfile中的动态舞台创建?

时间:2018-09-17 18:24:24

标签: jenkins jenkins-pipeline

我有3个可能并行发生的构建,它们的配置方式完全相同,但命令名称除外。我认为自动执行此操作会很不错,并且尝试了几个小时,采用了几种不同的方法,但都没有成功。如何完成动态创建并行阶段的步骤?

final String androidDockerImage = 'thyrlian/android-sdk:2.4'

pipeline {
    agent none
    options {
        timeout(time: 30, unit: 'MINUTES')
    }
    environment {
        IS_CI = 'true'
    }

    stages {

        stage('CI Build') {

            parallel {

                stage('Code Style') {
                    agent { docker { image androidDockerImage } }
                    steps {
                        sh './scripts/sign_android_sdk_agreement.sh'
                        sh './gradlew codeStyle'
                    }
                }

                stage('Lint') {
                    agent { docker { image androidDockerImage } }
                    steps {
                        sh './scripts/sign_android_sdk_agreement.sh'
                        sh './gradlew lint --stacktrace'
                    }
                }

                script {

                    ['Internal Debug', 'Internal Release', 'Production Release'].forEach { variantName ->
                       final String variant = variantName.replace(" ", "")
                        stage($variantName) {
                           agent { docker { image androidDockerImage } }
                           steps {
                               sh './scripts/sign_android_sdk_agreement.sh'
                               sh "./gradlew clean target-android:assemble$variant --stacktrace"
                           }
                           post {
                               always {
                                   junit "**/TEST-*.xml"
                               }
                           }
                        }
                    }

                }

            }

        }

    }
}

0 个答案:

没有答案