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?
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.
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>
Did you try to use
error('Failing build because...')
instead of
error "Foo"
What did you received? It is very strange that groovy find this 'error()' function, but with different argument, may be real problem that other library defined this function and groovy find wrong function instead of jenkins one.
Also strange name of Class due to exception should be something like
No signature of method: static full_package.Class.Funtion()
Could you debug this place in IDEA and check what is a strange class with name 'xxx' and without packages? I tried google strict phrase "No signature of method: static xxx." but it return nothing. May be it is something local in your project?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.