Pipeline when condition issue

19 views
Skip to first unread message

MDKF

unread,
Aug 28, 2018, 9:49:52 PM8/28/18
to Jenkins Users
Hi All,
 I have the following pipeline. I don't expect the steps in the when condition to run, but they are. Can anyone tell me what i'm doing wrong? (I know using an expression instead of a simple equals is overkill, but this is a simplified example to show my issue)
-Michael

pipeline {

 // Discarded: Promote Builds When...

 agent any
 environment {
Development = true
}
 stages {
    stage('test') {
    when {
        not {
            expression {
                Development == ~/(?i)(1|Y|YES|T|TRUE|ON|RUN)/
            }
        }
   }
   steps {
       echo 'Development is false'
    }
 }
 }
}

Devin Nusbaum

unread,
Aug 29, 2018, 11:44:50 AM8/29/18
to jenkins...@googlegroups.com
I think the problem is with your regex match. Based on http://mrhaki.blogspot.com/2009/09/groovy-goodness-matchers-for-regular.html, it looks like the operator to use is `==~`, but you have `== ~` with a space.

The stage is skipped correctly if I use `Development ==~ /(?i)(1|Y|YES|T|TRUE|ON|RUN)/` (remove the space before the ~).

--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f76ece7d-c962-4914-bdbd-c8addfb58ea9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Fowler

unread,
Aug 29, 2018, 11:55:45 AM8/29/18
to jenkins...@googlegroups.com
Thanks Devin, that worked!

You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/r2V5nHoKe04/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4C2474BB-A780-458B-9EBD-DFCB5C29F9BB%40cloudbees.com.
Reply all
Reply to author
Forward
0 new messages