首页 > 解决方案 > JenkinsFile 管道循环

问题描述

有没有人有pipeline{}一个循环的例子?

我试图通过使用循环在多个主机上运行相同的逻辑来“压缩”一个冗长且重复的 JenkinsFile。

...但是...我的piepline{}JenkinsFile 中没有正确的循环。

具体来说,我正在这样做......

pipeline {
    agent { label 'buildhost' }

    stages {
            stage("checks") {
                parallel {
                    // ['mac-amd64', 'linux-arm', 'win-amd64',  'linux-x86', 'linux-armv8', 'linux-amd64' ].each {
                    ['mac-amd64', 'linux-armv8', 'linux-amd64'].each {
                        host ->
                            stage("checks / ${host}") {
                                agent { label "buildhost-${host}" }
                                steps {
                                    dir ('peterlavalle.sbt/') {
                                        // combining these seemed to launch the SBT server which makes Jenkins hang
                                            sh 'java -Dsbt.log.noformat=true -jar ./sbt-launch.jar clean'
                                            sh 'java -Dsbt.log.noformat=true -jar ./sbt-launch.jar test'
                                            sh 'java -Dsbt.log.noformat=true -jar ./sbt-launch.jar publish'
                                    }

                                    ['cgc3.gradle/', 'kanobi.sbt/'].each {
                                        gradle ->
                                            dir (path) {
                                                sh 'chmod +=rwx ./gradlew'
                                                sh './gradlew --stacktrace --console=plain clean'
                                                sh './gradlew --stacktrace --console=plain check'
                                                sh './gradlew --stacktrace --console=plain publish'
                                            }
                                    }
                                    dir ("coffeeskript.cgc/") {
                                        sh 'chmod +=rwx ./gradlew'
                                        sh './gradlew --stacktrace --console=plain check'
                                    }
                                }
                            }
                    }
                }
            }
        }
    }
}

......詹金斯说“这里只有阶段!” 或类似的。

...
...
...
Running in Durability level: MAX_SURVIVABILITY
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 47: Expected a stage @ line 47, column 11.
                         ['mac-amd64', 'linux-armv8', 'linux-amd64'].each {
                         ^

WorkflowScript: 44: Expected one of "steps", "stages", or "parallel" for stage "checks" @ line 44, column 4.
                stage("checks") {
            ^
...
...
...

标签: jenkinsjenkins-pipeline

解决方案


推荐阅读