groovy管道脚本中的“在步骤之间找不到这样的DSL方法'$'”错误

时间:2019-10-24 21:55:32

标签: groovy jenkins-pipeline

我的第一个管道脚本抛出如下错误:

Also:   java.lang.NoSuchMethodError: No such DSL method '$' found among steps [ <big text here>]

它按预期触发了下游_1和下游_2作业,但最终因上述错误而失败,这是我拥有的常规脚本,有任何帮助/指针来解决此问题吗?

pipeline {
agent
{
    node {
            label 'my_server'
          }
}

stages 
{
    stage('Start') {
        steps {
            sh 'ls'
        }
    }

    stage('End') {
        steps {
            script {
            def jobsString = "downstream_1,downstream_2"
            ArrayList jobsList = jobsString.split('\\,')

            def parallelJobs2Run = [:]
            jobsList.each { job ->
                echo "Run parallel for job ${job}"
                parallelJobs2Run["${job}"] = { ->
                    echo "Calling job ${job}"
                    jobResults=build job: "${job}",
                    parameters: [
                        string(name: 'param1', value: "value1"),
                        string(name: 'param2', value: "value2")
                    ],
                    propagate: true,
                    wait: true
                    buildNumber = ${jobResults.number}
                    echo "${job} Build number |${buildNumber}| result: |${jobResults.result}|"
                    echo "See details on: |${jobResults.absoluteUrl}|"
                }
            };
            parallel parallelJobs2Run
            }
        }
    }
}
}

1 个答案:

答案 0 :(得分:0)

此行

buildNumber = ${jobResults.number}

应该是

buildNumber = jobResults.number

buildNumber = "${jobResults.number}"