Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-47053

Using environment in when block leads to unknown conditional error

      After updating to the latest version of the Pipeline Model Definition Plugin I get the following error:

       

      WorkflowScript: 43: Unknown conditional error. Valid conditionals are: allOf, anyOf, branch, changelog, changeset, environment, expression, not @ line 43, column 21.
       environment name: 'CONTINUE', value: 'yes'
       ^

      The whole block looks like this

      stage('stage') {
        when {
          environment name: 'CONTINUE', value: 'yes'
        }
        steps {
          do something
        }
      }
      

          [JENKINS-47053] Using environment in when block leads to unknown conditional error

          Andrew Bayer added a comment -

          I wrote a whole epic here about my attempts to figure out what was going on, since it made no sense and I can't reproduce it. But I just noticed something truly weird:

          WorkflowScript: 43: Unknown conditional error. Valid conditionals are: allOf, anyOf, branch, changelog, changeset, environment, expression, not @ line 43, column 21.
          

          Specifically, Unknown conditional error - that means something went wrong, in theory, with parsing environment as a String literal, which...yeah. Never actually seen that, and it should have thrown up another error for that.

          Is there any way you can get me the entire Jenkinsfile? Something somewhere is really broken with parsing your Jenkinsfile and I can't reproduce it just from your example.

          Andrew Bayer added a comment - I wrote a whole epic here about my attempts to figure out what was going on, since it made no sense and I can't reproduce it. But I just noticed something truly weird: WorkflowScript: 43: Unknown conditional error. Valid conditionals are: allOf, anyOf, branch, changelog, changeset, environment, expression, not @ line 43, column 21. Specifically, Unknown conditional error - that means something went wrong, in theory, with parsing environment as a String literal, which...yeah. Never actually seen that, and it should have thrown up another error for that. Is there any way you can get me the entire Jenkinsfile ? Something somewhere is really broken with parsing your Jenkinsfile and I can't reproduce it just from your example.

          Andrew Bayer added a comment -

          Also, are there any other errors anywhere or just that one?

          Andrew Bayer added a comment - Also, are there any other errors anywhere or just that one?

          There are no other errors. I replaced the line with

          expression { env.CONTINUE_DEPLOYMENT == 'yes' }
          

          and everything works fine.
          I'll attach the whole file. I just removed the shell script calls that use the parameters.

          Waldemar Wukowa added a comment - There are no other errors. I replaced the line with expression { env.CONTINUE_DEPLOYMENT == 'yes' } and everything works fine. I'll attach the whole file. I just removed the shell script calls that use the parameters.

          Andrew Bayer added a comment -

          Hrrrrm, it works for me. What happens if you try running the Jenkinsfile you attached, but with echo "Wie gehts?" or something else in the steps blocks?

          Andrew Bayer added a comment - Hrrrrm, it works for me. What happens if you try running the Jenkinsfile you attached, but with echo "Wie gehts?" or something else in the steps blocks?

          I figured out the probem. I ran this one as pipeline and it led somehow to this error, maybe I just had been confused because it was friday afternoon.

          This pipeline is defined as global variable, because it's how our main deploy pipeline looks like. So there is a parameter named "environment" after removing this one, everything works fine again. Sorry for misleading you, because I somehow thought it wasn't related to being defined as a global var.

          So after changing this

          def call(environment, mainHost, backupHost) {
              pipeline {...}
          }
          

          to

          def call(deployEnv, mainHost, backupHost) {
              pipeline {...}
          }
          

          Everything is fine again.
           

           

          Waldemar Wukowa added a comment - I figured out the probem. I ran this one as pipeline and it led somehow to this error, maybe I just had been confused because it was friday afternoon. This pipeline is defined as global variable, because it's how our main deploy pipeline looks like. So there is a parameter named "environment" after removing this one, everything works fine again. Sorry for misleading you, because I somehow thought it wasn't related to being defined as a global var. So after changing this def call(environment, mainHost, backupHost) { pipeline {...} } to def call(deployEnv, mainHost, backupHost) { pipeline {...} } Everything is fine again.    

          Andrew Bayer added a comment -

          Aaaah. That's annoying but understandable. =)

          Andrew Bayer added a comment - Aaaah. That's annoying but understandable. =)

          Liam Newman added a comment -

          Bulk closing resolved issues.

          Liam Newman added a comment - Bulk closing resolved issues.

            abayer Andrew Bayer
            riffert Waldemar Wukowa
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: