Charlie
Charlie

Reputation: 1746

Custom function in Delcarative Pipeline?

I have this simple pipeline (I'm using a more complex but this one reproduces it):

def test(String name) {
    println test
}

pipeline {
    agent {
        dockerfile {
            label "jenkins-lnx-slave3"
            args "--user root:root"
            dir "CICD"
        }
    }

    stages {
        stage ('Test') {
            steps {
                test(name: 'Hello')
            }
        }
    }
}

And Jenkins is giving me this "No Such DSL method 'test' found" error:

> [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node
> [Pipeline] End of Pipeline java.lang.NoSuchMethodError: No such DSL
> method 'test' found among steps [ArtifactoryGradleBuild,

This goes on and on for many lines. Am I doing the custom function correctly?

Anyone have any ideas?

Upvotes: 2

Views: 1238

Answers (1)

Vasiliki Siakka
Vasiliki Siakka

Reputation: 1283

You're trying to call test with a named argument and that's causing the breakage. This post explains what's happening when you try to use named params in groovy.

Additionally, you have a typo inside test: println test should be println name.

Upvotes: 4

Related Questions