詹金斯找不到定义的功能?

时间:2019-01-01 15:24:14

标签: groovy jenkins-pipeline

我写这是为了测试我在JENKINS-44085上看到的想法

def generateStage(String job, String targetVersion,
                  String rootVersion, Integer sleepTime=0) {
    return {
        stage("Deploying: ${job}") {
            sleep sleepTime
            println "Job: $job"
        }
    }
}

def deployProcs(targetVersion, rootVersion) {
    script {
        int sleepTime = 0
        def procs = ["proc-proc", "proc-proc-high"]
        def parallelStagesMap = procs.collectEntries {
            ["${it}" : generateStage(it, targetVersion, rootVersion, sleepTime)]
            sleepTime += 5
        }
        timestamps {
            parallel parallelStagesMap
        }
    }
}

node('linux') {
  deployProcs(10, 10)
}

但是我明白了

java.lang.NoSuchMethodError: No such DSL method 'generateStage' found among steps.

我想念什么?

1 个答案:

答案 0 :(得分:1)

您正在呼叫deployProcs(10, 10),其中两个参数都是Integer的类型。调用generateStage时使用相同的整数参数,这些参数的类型分别为String targetVersionString rootVersion

一种解决方法是调用deployProcs('10', '10')或更改def generateStage(String job, Integer targetVersion, Integer rootVersion, Integer sleepTime=0),或从generateStage函数参数中删除类型。