Unable to use the "when" closure to skip a stage (pipeline-model-definition-plugin)

1,972 views
Skip to first unread message

Roi Aldaag

unread,
Feb 9, 2017, 5:07:37 AM2/9/17
to Jenkins Users
After updating the last pipeline plugin 2.5 and dependent plugins on latest Jenkins 2.45 we are unable to use the "when" closure:

we get the following error:

java.lang.NoSuchMethodError: No such DSL method 'when' found among steps [...]
	at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:149)


for a very simple pipeline in the inline pipeline editor (not in an external Jenkinsfile):

node {
   stage('1') { // for display purposes

   }
   stage('2') {
        when {
            //return false
        }
   }
   stage('3') {

   }
}

Does the last release of pipeline-model-definition-plugin 1.0 include the support for the "when" closure in a stage?

Thank you in advance,

Roi

R. Tyler Croy

unread,
Feb 9, 2017, 5:11:46 AM2/9/17
to jenkins...@googlegroups.com
(replies inline)

On Thu, 09 Feb 2017, Roi Aldaag wrote:

> for a very simple pipeline in the inline pipeline editor (not in an
> external Jenkinsfile):
>
> *node {*
> * stage('1') { // for display purposes*
>
> * }*
> * stage('2') {*
> * when {*
> * //return false*
> * }*
> * }*
> * stage('3') {*
>
> * }*
> *}*


This Jenkinsfile is _not_ a Declarative Pipeline but is instead using the
Scripted Pipeline syntax.

A Declarative Pipeline *must* have a `pipeline { }` outer block, and a number
of other required sections, and `when` is only applicable within Declarative.
Otherwise you can just use normal Groovy conditionals.

See this document for more: https://jenkins.io/doc/book/pipeline/syntax/

- R. Tyler Croy

------------------------------------------------------
Code: <https://github.com/rtyler>
Chatter: <https://twitter.com/agentdero>
xmpp: rty...@jabber.org

% gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
signature.asc

Roi Aldaag

unread,
Feb 9, 2017, 7:51:59 AM2/9/17
to Jenkins Users
Thanks Tyler for your prompt response!

Just to make it clear -  the "when" clause is NOT supported in the Scripted Pipeline syntax and is only supported in the Declarative Pipeline Jenkinsfile? 
Is that explained anywhere in the documentation? Aren't those scripts interpreted eventually by the same engine?

I am aware that the Declarative pipeline should start with the pipeline outer block. The code that I have posted was for a scripted pipeline and I have stated that in my original post.

Thanks,

Roi

Baptiste Mathus

unread,
Feb 17, 2017, 2:47:36 AM2/17/17
to jenkins...@googlegroups.com
"scripted" Pipeline simply uses typical programmatic "if" construct.

Declarative makes this more, well, declarative and is a bit different for readability purpose.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/38a2f213-9acc-4101-b9c8-f588286eeb08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages