[JIRA] (JENKINS-41645) Better error messages when illegal identifiers are used in an `environment` block

2 views
Skip to first unread message

chris@orr.me.uk (JIRA)

unread,
Feb 1, 2017, 8:02:01 PM2/1/17
to jenkinsc...@googlegroups.com
Christopher Orr created an issue
 
Jenkins / Improvement JENKINS-41645
Better error messages when illegal identifiers are used in an `environment` block
Issue Type: Improvement Improvement
Assignee: Andrew Bayer
Components: pipeline-model-definition-plugin
Created: 2017/Feb/02 1:01 AM
Environment: Plugin 1.0
Priority: Minor Minor
Reporter: Christopher Orr

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.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.1.7#71011-sha1:2526d7c)
Atlassian logo

chris@orr.me.uk (JIRA)

unread,
Feb 1, 2017, 9:11:01 PM2/1/17
to jenkinsc...@googlegroups.com
Christopher Orr commented on Improvement JENKINS-41645
 
Re: Better error messages when illegal identifiers are used in an `environment` block

Another one is quoted names:

environment {
  // Failure [what-about-single-quotes] is a constant expression, but it should be a variable 
  'what-about-single-quotes' = 'unlikely'
}

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:15:01 AM2/6/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:18:01 AM2/6/17
to jenkinsc...@googlegroups.com

Ok, 456_XYZ I can't do anything about - that's a Groovy compilation error, so it's happening before we get to the linting.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:19:01 AM2/6/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:22:01 AM2/6/17
to jenkinsc...@googlegroups.com

Ok, I did do the check right, I'm just not reporting it right. Oy.

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:47:01 AM2/6/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:47:01 AM2/6/17
to jenkinsc...@googlegroups.com
Andrew Bayer started work on Improvement JENKINS-41645
 
Change By: Andrew Bayer
Status: Open In Progress

andrew.bayer@gmail.com (JIRA)

unread,
Feb 6, 2017, 3:47:01 AM2/6/17
to jenkinsc...@googlegroups.com

scm_issue_link@java.net (JIRA)

unread,
Feb 21, 2017, 12:09:01 PM2/21/17
to jenkinsc...@googlegroups.com
SCM/JIRA link daemon commented on Improvement JENKINS-41645
 
Re: Better error messages when illegal identifiers are used in an `environment` block

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/EnvironmentTest.java
pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
pipeline-model-definition/src/test/resources/errors/envIdentifierDigitsUnderscore.groovy
pipeline-model-definition/src/test/resources/errors/envIdentifierHyphens.groovy
pipeline-model-definition/src/test/resources/errors/envIdentifierStartingWithDigit.groovy
pipeline-model-definition/src/test/resources/errors/envIdentifierString.groovy
pipeline-model-definition/src/test/resources/errors/envIdentifiersCaughtInternally.groovy
pipeline-model-definition/src/test/resources/simpleEnvironment.groovy
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/4b8ddf1e03419ec762cfd74ffa0fe0860f32d0e6
Log:
Merge pull request #106 from abayer/jenkins-41645

JENKINS-41645 Better validation for non-binary expressions in env

Compare: https://github.com/jenkinsci/pipeline-model-definition-plugin/compare/20f8126272bb...4b8ddf1e0341

scm_issue_link@java.net (JIRA)

unread,
Feb 21, 2017, 12:09:02 PM2/21/17
to jenkinsc...@googlegroups.com

Code changed in jenkins
User: Andrew Bayer
Path:
pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties

pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
pipeline-model-definition/src/test/resources/errors/invalidEnvironmentIdentifiers.groovy
http://jenkins-ci.org/commit/pipeline-model-definition-plugin/fffa3bca1d7b0559bb166d78f95d1dd3b8da9dff
Log:


JENKINS-41645 Better validation for non-binary expressions in env

We can't handle all invalid environment identifiers currently - things
like 123_ABC or something-with-hyphens or 'somethingInQuotes' all end
up failing out at initial Groovy compilation, before we get the AST to
work with. We do catch those when coming from JSON, which is
something. But until this, we didn't give useful errors for any
invalid environment identifier that actually gets through compilation

  • i.e., 3D_GLASSES, 123ABC. Those aren't BinaryExpressions, so they
    were skipped and we ended up with just the general error case
    reporting. This commit changes that. =)

andrew.bayer@gmail.com (JIRA)

unread,
Feb 21, 2017, 12:10:03 PM2/21/17
to jenkinsc...@googlegroups.com

bitwiseman@gmail.com (JIRA)

unread,
Oct 22, 2019, 11:25:47 PM10/22/19
to jenkinsc...@googlegroups.com
Liam Newman closed an issue as Fixed
 

Bulk closing resolved issues.

Change By: Liam Newman
Status: Resolved Closed
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages