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

Using environment in when block leads to unknown conditional error

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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
        }
      }
      

        Attachments

          Activity

          Hide
          abayer 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.

          Show
          abayer 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.
          Hide
          abayer Andrew Bayer added a comment -

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

          Show
          abayer Andrew Bayer added a comment - Also, are there any other errors anywhere or just that one?
          Hide
          riffert 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.

          Show
          riffert 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.
          Hide
          abayer 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?

          Show
          abayer 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?
          Hide
          riffert 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.
           

           

          Show
          riffert 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.    
          Hide
          abayer Andrew Bayer added a comment -

          Aaaah. That's annoying but understandable. =)

          Show
          abayer Andrew Bayer added a comment - Aaaah. That's annoying but understandable. =)
          Hide
          bitwiseman Liam Newman added a comment -

          Bulk closing resolved issues.

          Show
          bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

            People

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

              Dates

              Created:
              Updated:
              Resolved: