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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

Adrian Wyssmann
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?

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/40965400-9f4d-4dbf-8375-35558fb0f731n%40googlegroups.com.