Skip to content
Permalink
Browse files
[FIXED JENKINS-37928] Properly detect sections without values.
The exact error message could be better - I need to understand what
other possible ways this could fail to be a method call expression
besides just not having arguments, but this should be general enough a
message for all possibilities for now.
  • Loading branch information
abayer committed Sep 2, 2016
1 parent 1ddd0ff commit 8c7d333f41651bb7b1ca0fcc98c1bb45ef8beb96
@@ -118,35 +118,39 @@ class ModelParser {
def sectionsSeen = new HashSet();
eachStatement(pipelineBlock.body.code) { stmt ->
def mc = matchMethodCall(stmt);
def name = parseMethodName(mc);
// Here, method name is a "section" name at the top level of the "pipeline" closure, which must be unique.
if (!sectionsSeen.add(name)) {
// Also an error that we couldn't actually detect at model evaluation time.
errorCollector.error(r,"Multiple occurences of the $name section")
}
if (mc == null) {
errorCollector.error(r, "Not a valid section definition: '${getSourceText(stmt)}'")
} else {
def name = parseMethodName(mc);
// Here, method name is a "section" name at the top level of the "pipeline" closure, which must be unique.
if (!sectionsSeen.add(name)) {
// Also an error that we couldn't actually detect at model evaluation time.
errorCollector.error(r, "Multiple occurrences of the $name section")
}

switch (name) {
case 'stages':
r.stages = parseStages(stmt);
break;
case 'environment':
r.environment = parseEnvironment(stmt);
break;
case 'notifications':
r.notifications = parseNotifications(stmt);
break;
case 'postBuild':
r.postBuild = parsePostBuild(stmt);
break;
case 'agent':
r.agent = parseAgent(stmt);
break;
case 'tools':
r.tools = parseTools(stmt)
break
default:
// We need to check for unknowns here.
errorCollector.error(r, "Undefined section '$name'")
switch (name) {
case 'stages':
r.stages = parseStages(stmt);
break;
case 'environment':
r.environment = parseEnvironment(stmt);
break;
case 'notifications':
r.notifications = parseNotifications(stmt);
break;
case 'postBuild':
r.postBuild = parsePostBuild(stmt);
break;
case 'agent':
r.agent = parseAgent(stmt);
break;
case 'tools':
r.tools = parseTools(stmt)
break
default:
// We need to check for unknowns here.
errorCollector.error(r, "Undefined section '$name'")
}
}
}

@@ -130,14 +130,20 @@ public void duplicateStepParameter() throws Exception {
failWithError("Duplicate named parameter 'time' found");
}


@Test
public void emptyEnvironment() throws Exception {
prepRepoWithJenkinsfile("errors", "emptyEnvironment");

failWithError("No variables specified for environment");
}

@Test
public void emptyAgent() throws Exception {
prepRepoWithJenkinsfile("errors", "emptyAgent");

failWithError("Not a valid section definition: 'agent'");
}

@Test
public void invalidBuildCondition() throws Exception {
prepRepoWithJenkinsfile("errors", "invalidBuildCondition");
@@ -0,0 +1,36 @@
/*
* The MIT License
*
* Copyright (c) 2016, 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 {
agent

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



0 comments on commit 8c7d333

Please sign in to comment.