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

64 views
Skip to first unread message

Adrian Wyssmann

unread,
Dec 15, 2020, 5:49:15 AM12/15/20
to Jenkins Users
I have the following shared-library file defaultCiPipelineGeneric.groovy

def call(body) {
    // evaluate the body block, and collect configuration into the object
    def pipelineParams= [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = pipelineParams
    body()

    pipelineParams = initializePipeline(pipelineParams, pipelineParams.buildType)

    pipeline {
        agent {
            label pipelineParams.nodes
        }
    ...


The pipeline is then uses as follows (e.g. in jenkins-pipeline-demo-generic):
library identifier: "pipeline-helper@master"

defaultCiPipelineGeneric {
    nodes               = 'windows-test'
    buildScript         = 'build.groovy'
}

That actually works fine. Now If i introduce additional methods like this:
def call(body) {
    this.call(body, null)
}

def call(body, buildFunction) {
    this.call(body, null, null)
}

def call(body, buildFunction, deployFunction) {
    // evaluate the body block, and collect configuration into the object
    def pipelineParams= [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = pipelineParams
    body()

    pipelineParams = initializePipeline(pipelineParams, pipelineParams.buildType)

    pipeline {
        agent {
            label pipelineParams.nodes
        }

This fails with java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps

Why does that not work?
Reply all
Reply to author
Forward
0 new messages