JenkinsPipelineUnit icon indicating copy to clipboard operation
JenkinsPipelineUnit copied to clipboard

No signature of method: com.lesfurets.jenkins.unit.declarative.WhenDeclaration.not()

Open Angelina1984 opened this issue 4 years ago • 3 comments

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)

Angelina1984 avatar May 25 '20 21:05 Angelina1984

I tried adding helper.registerAllowedMethod('not', [Closure.class], null) in setup() but it's still showing same error.

Angelina1984 avatar May 25 '20 21:05 Angelina1984

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

stchar avatar Jul 23 '20 14:07 stchar

This appears to have a fix in f7f03c3

shanethehat avatar Sep 16 '20 16:09 shanethehat