Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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. =)
  • Loading branch information
abayer committed Feb 15, 2017
1 parent 736b3c4 commit fffa3bc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Expand Up @@ -240,6 +240,9 @@ class ModelParser implements Parser {
return
}
}
} else {
ModelASTKey badKey = new ModelASTKey(exp)
errorCollector.error(badKey, Messages.ModelParser_InvalidEnvironmentIdentifier(getSourceText(exp)))
}
}
errorEncountered = true
Expand Down
Expand Up @@ -53,6 +53,7 @@ ModelParser.ExpectedTool=Expected to find 'someTool "someVersion"'
ModelParser.ExpectedTrigger=Expected a trigger
ModelParser.InvalidAgent=Only "agent none", "agent any" or "agent '{'...}" are allowed.
ModelParser.InvalidBuildCondition=The 'post' section can only contain build condition names with code blocks. Valid condition names are {0}
ModelParser.InvalidEnvironmentIdentifier="{0}" is not a valid environment expression. Use "key = value" pairs with valid Java/shell keys.
ModelParser.InvalidSectionDefinition=Not a valid section definition: "{0}". Some extra configuration is required.
ModelParser.InvalidStageSectionDefinition=Not a valid stage section definition: "{0}". Some extra configuration is required.
ModelParser.MapNotAllowed={0} cannot be defined as maps
Expand Down
Expand Up @@ -492,6 +492,14 @@ public void dirSepInDockerfileName() throws Exception {
.go();
}

@Issue("JENKINS-41645")
@Test
public void invalidEnvironmentIdentifiers() throws Exception {
expectError("invalidEnvironmentIdentifiers")
.logContains(Messages.ModelParser_InvalidEnvironmentIdentifier("1FOO = \"BLARGH\""))
.go();
}

@Issue("JENKINS-39799")
@Test
public void badPostContent() throws Exception {
Expand Down
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
environment {
1FOO = "BLARGH"
FOO = "BAR"
}

agent {
label "some-label"
}

stages {
stage("foo") {
steps {
sh 'echo "FOO is $FOO"'
}
}
}
}



0 comments on commit fffa3bc

Please sign in to comment.