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

Provide more clear instructions when referencing a variable in environment {}

    XMLWordPrintable

Details

    Description

      In a Declarative Pipeilne which defines an environment variable which is derivative of a built-in, e.g.

      pipeline {
        environment {
          MY_SHA=GIT_COMMIT
        }
      }
      

      This results in this error:

      hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /var/jenkins_home/jobs/cloudbees-training/jobs/training-commons/branches/PR-143/builds/1/libs/training-commons/vars/commonTrainingPipeline.groovy: 16: Environment variable values must either be strings or function calls. @ line 16, column 24.
               MY_SHA=GIT_COMMIT
                                ^
      /var/jenkins_home/jobs/cloudbees-training/jobs/training-commons/branches/PR-143/builds/1/libs/training-commons/vars/commonTrainingPipeline.groovy: 13: No variables specified for environment @ line 13, column 5.
             environment {
             ^
      2 errors
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      

      The easy solution here is to quote the variable, e.g.:

      environment {
        MY_SHA="${GIT_COMMIT}"
      } 
      

      I understand why this is so, but I think the error message and the resulting solution are confusing and not intuitive to most Declarative Pipeline users.

      A better, more task-oriented error message would be helfpful IMHO

      Attachments

        Issue Links

          Activity

            People

              abayer Andrew Bayer
              rtyler R. Tyler Croy
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: