JenkinsPipelineUnit
JenkinsPipelineUnit copied to clipboard
No signature of method: com.lesfurets.jenkins.unit.declarative.WhenDeclaration.not()
class TestJenkins extends DeclarativePipelineTest {
@Override
@Before
void setUp() throws Exception {
...
}
@Test
void shouldExecutePipelineMethod_fromWpeSharedLibrary(){
runScript('Jenkinsfile')
}
}
Jenkinsfile
pipeline {
agent {
node {
label 'centos'
}
}
triggers { cron('H 1 * * *') }
stages {
stage('Prepare') {
when {
not { triggeredBy 'TimerTrigger' }
}
steps {
script {
...
}
}
}
}
}
I receive following error:
No signature of method: com.lesfurets.jenkins.unit.declarative.WhenDeclaration.not() is applicable for argument types: (Jenkinsfile$_run_closure1$_closure5$_closure7$_closure8$_closure10) values: [Jenkinsfile$_run_closure1$_closure5$_closure7$_closure8$_closure10@64088b01]
Possible solutions: notify(), wait(), any(), wait(long), any(groovy.lang.Closure), is(java.lang.Object)
groovy.lang.MissingMethodException: No signature of method: com.lesfurets.jenkins.unit.declarative.WhenDeclaration.not() is applicable for argument types: (Jenkinsfile$_run_closure1$_closure5$_closure7$_closure8$_closure10) values: [Jenkinsfile$_run_closure1$_closure5$_closure7$_closure8$_closure10@64088b01]
Possible solutions: notify(), wait(), any(), wait(long), any(groovy.lang.Closure), is(java.lang.Object)
..
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at Jenkinsfile$_run_closure1$_closure5$_closure7$_closure8.doCall(Jenkinsfile:46)
I tried adding helper.registerAllowedMethod('not', [Closure.class], null)
in setup()
but it's still showing same error.
Hi @Angelina1984, sorry for a late response to fix you issue you need to tweak WhenDeclaration
class
https://github.com/jenkinsci/JenkinsPipelineUnit/blob/f12bed2e8b52b72d392c776b55e5a346a65f1de3/src/main/groovy/com/lesfurets/jenkins/unit/declarative/WhenDeclaration.groovy
Unfortunately declarative pipeline support in this project has a lack of features
This appears to have a fix in f7f03c3