Search code examples
javamavenjenkinsintellij-ideagroovy

What library does contain basic jenkins workflow groovy functions?


I am writing a junit test for my Jenkins groovy scripts. My Jenkins script that I am testing contains a method call like this:

error "Foo"

When I try to run the test from my IDE (Intellij IDEA) I get an error like this:

No signature of method: static xxx.error() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values [Foo]

So I suppose, I need to add some library into my classpath to make this error function known to Runtime. I tried this maven dependency

        <dependency>
            <groupId>org.jenkins-ci.plugins.workflow</groupId>
            <artifactId>workflow-aggregator</artifactId>
            <version>2.5</version>
        </dependency>

but it does't help.

So I am struggling to find what library contains these basic Jenkins workflow functions described in here: https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps

Any ideas?


Solution

  • The solution is to use Jenkins Pipeline Unit library that makes all those functions/methods like echo or error available and known to the pipeline context:

    ...
    helper.registerAllowedMethod("echo", [String.class], null)
    ...
    

    In this case every test should wrap-up the piece of code we are trying to test into a small jenkins script that will be executed by the JenkinsPipelineUnit engine.