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

Better error messages when illegal identifiers are used in an `environment` block

XMLWordPrintable

      Presumably environment variable names must be legal Groovy identifiers (although generally, I don't think environment variables have as a strict a naming convention).

      When trying to use various illegal identifiers, I got various different error messages:

      pipeline {
        agent any
        stages {
          stage('Foo') {
              environment {
                // Failure: Expected name=value pairs
                3D_GLASSES = 'no'
                
                // Failure: Expected name=value pairs
                123ABC = 'bad'
      
                // Failure: expecting token in range: '0'..'9', found 'X'
                456_XYZ = 'numeric literal?'
      
                // Failure: ((what - about) - hyphens) is a binary expression
                what-about-hyphens = 'binary expression?'
      
                // OK
                LEGAL_GROOVY_IDENTIFIER = 'yay'
              }
              steps {
                sh 'env'
              }
          }
        }
      }
      

      I would expect some linting when editing the Pipeline (well, the editor does catch the 456_XYZ case), and nicer error messages at runtime.

            abayer Andrew Bayer
            orrc Christopher Orr
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: