Reputation: 34900
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?
Upvotes: 2
Views: 113
Reputation: 34900
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.
Upvotes: 1
Reputation: 14584
The source is located here. So based on the pom I would say it's in the following dependency.
<!-- https://mvnrepository.com/artifact/org.jenkins-ci.plugins.workflow/workflow-basic-steps -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.24</version>
<scope>test</scope>
</dependency>
Upvotes: 0