Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-45081] Don't error out for foo.pipeline { ... }
  • Loading branch information
abayer committed Jul 6, 2017
1 parent 7ae93aa commit 8533d4c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
Expand Up @@ -118,11 +118,12 @@ class ModelParser implements Parser {
// first, quickly ascertain if this module should be parsed at all
// TODO: 'use script' escape hatch
def pst = src.statementBlock.statements.find {
matchMethodCall(it)?.methodAsString == ModelStepLoader.STEP_NAME
MethodCallExpression m = matchMethodCall(it)
return m != null && matchMethodName(m) == ModelStepLoader.STEP_NAME
}

if (pst==null) {
// Check if there's a 'pipeline' step somewhere nexted within the other statements and error out if that's the case.
// Check if there's a 'pipeline' step somewhere nested within the other statements and error out if that's the case.
src.statementBlock.statements.each { checkForNestedPipelineStep(it) }
return null; // no 'pipeline', so this doesn't apply
}
Expand Down
Expand Up @@ -312,7 +312,8 @@ protected void initGlobalLibrary() throws IOException {
"def hello(name) {echo \"Hello ${name}\"}",
"def foo(x) { this.x = x+'-set'; }",
"def bar() { return x+'-get' }",
"def baz() { return 'nothing here' }")
"def baz() { return 'nothing here' }",
"def pipeline(Closure c) { c.call() }")
, "\n"));
FileUtils.writeStringToFile(new File(vars, "returnAThing.groovy"), StringUtils.join(Arrays.asList(
"def call(a) { return \"${a} tada\" }"), "\n"
Expand Down
Expand Up @@ -345,6 +345,16 @@ public void globalLibrarySuccess() throws Exception {
.go();
}

@Issue("JENKINS-45081")
@Test
public void objectMethodPipelineCall() throws Exception {
initGlobalLibrary();

expect("objectMethodPipelineCall")
.logContains("Hi there")
.go();
}

@Test
public void basicWhen() throws Exception {
expect("basicWhen")
Expand Down
@@ -0,0 +1,27 @@
/*
* 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.
*/

acmeVar.pipeline {
echo "Hi there"
}

0 comments on commit 8533d4c

Please sign in to comment.