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

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

    Details

    • Similar Issues:

      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

            Hide
            abayer Andrew Bayer added a comment -

            How would "Environment variable values must either be strings or function calls. Try wrapping the value in "${(value)}" instead." be?

            Show
            abayer Andrew Bayer added a comment - How would "Environment variable values must either be strings or function calls. Try wrapping the value in "${(value)}" instead." be?
            Hide
            abayer Andrew Bayer added a comment -

            Ignore that noise. How about "Environment variable values must either be strings in single or double quotes, or function calls."?

            Show
            abayer Andrew Bayer added a comment - Ignore that noise. How about "Environment variable values must either be strings in single or double quotes, or function calls."?
            Hide
            abayer Andrew Bayer added a comment - - edited

            heh. Changing it up again to "Environment variable values must either be single quoted, double quoted, or function calls." - more consistent with the error message if you do weird things with concatenated environment values (i.e., 1 + "2" will give you "Environment variable values to be concatenated together must be single or double quoted.").

            And yes, this message is still trusting that people understand how to reference a variable inside a string, but I think that's general-knowledge enough to not be worth the verbosity here.

            Show
            abayer Andrew Bayer added a comment - - edited heh. Changing it up again to "Environment variable values must either be single quoted, double quoted, or function calls." - more consistent with the error message if you do weird things with concatenated environment values (i.e., 1 + "2" will give you "Environment variable values to be concatenated together must be single or double quoted."). And yes, this message is still trusting that people understand how to reference a variable inside a string, but I think that's general-knowledge enough to not be worth the verbosity here.
            Hide
            abayer Andrew Bayer added a comment -

            PR up with the wording I mentioned in the comment above - https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/238

            Show
            abayer Andrew Bayer added a comment - PR up with the wording I mentioned in the comment above - https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/238
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Andrew Bayer
            Path:
            pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
            http://jenkins-ci.org/commit/pipeline-model-definition-plugin/8f8b158545fa7f6e9af2dcbcdd065e339a769cb3
            Log:
            [FIXED JENKINS-48758] Better message about allowed env values

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties http://jenkins-ci.org/commit/pipeline-model-definition-plugin/8f8b158545fa7f6e9af2dcbcdd065e339a769cb3 Log: [FIXED JENKINS-48758] Better message about allowed env values
            Hide
            abayer Andrew Bayer added a comment -

            Alright, merged and it'll be in 1.2.7.

            Show
            abayer Andrew Bayer added a comment - Alright, merged and it'll be in 1.2.7.
            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:
                rtyler R. Tyler Croy
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: