Skip to content

Commit

Permalink
Merge pull request #79 from abayer/jenkins-40580
Browse files Browse the repository at this point in the history
[FIXED JENKINS-40580] Quote parallel branch names
  • Loading branch information
abayer committed Jan 5, 2017
2 parents 57c7a47 + ed9fd68 commit fbfb5ab
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 2 deletions.
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringEscapeUtils;
import org.jenkinsci.plugins.pipeline.modeldefinition.validator.ModelValidator;

/**
Expand Down Expand Up @@ -112,7 +113,10 @@ public String toGroovy() {
result.append(',');
}
result.append('\n');
result.append(branch.getName()).append(": {\n").append(branch.toGroovy()).append("\n}");
result.append('"' + StringEscapeUtils.escapeJava(branch.getName()) + '"')
.append(": {\n")
.append(branch.toGroovy())
.append("\n}");
}
if (failFast != null && failFast) {
result.append(",\nfailFast: true");
Expand Down
Expand Up @@ -131,7 +131,9 @@ public void setUp() throws Exception {
"environmentInStage",
"basicWhen",
"skippedWhen",
"parallelPipelineWithFailFast"
"parallelPipelineWithFailFast",
"parallelPipelineWithSpaceInBranch",
"parallelPipelineQuoteEscaping"
);

public static Iterable<Object[]> configsWithErrors() {
Expand Down
Expand Up @@ -160,6 +160,20 @@ public void parallelPipeline() throws Exception {
.go();
}

@Test
public void parallelPipelineQuoteEscaping() throws Exception {
expect("parallelPipelineQuoteEscaping")
.logContains("[Pipeline] { (foo)", "[first] { (Branch: first)", "[\"second\"] { (Branch: \"second\")")
.go();
}

@Test
public void parallelPipelineWithSpaceInBranch() throws Exception {
expect("parallelPipelineWithSpaceInBranch")
.logContains("[Pipeline] { (foo)", "[first one] { (Branch: first one)", "[second one] { (Branch: second one)")
.go();
}

@Test
public void parallelPipelineWithFailFast() throws Exception {
expect("parallelPipelineWithFailFast")
Expand Down
@@ -0,0 +1,31 @@
{"pipeline": {
"stages": [ {
"name": "foo",
"branches": [
{
"name": "first",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "First branch"
}
}]
},
{
"name": "\"second\"",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "Second branch"
}
}]
}
]
}],
"agent": {
"isLiteral": true,
"value": "none"
}
}}
@@ -0,0 +1,31 @@
{"pipeline": {
"stages": [ {
"name": "foo",
"branches": [
{
"name": "first one",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "First branch"
}
}]
},
{
"name": "second one",
"steps": [ {
"name": "echo",
"arguments": {
"isLiteral": true,
"value": "Second branch"
}
}]
}
]
}],
"agent": {
"isLiteral": true,
"value": "none"
}
}}
@@ -0,0 +1,42 @@
/*
* 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 none
stages {
stage("foo") {
steps {
parallel(first: {
echo "First branch"
},
'"second"': {
echo "Second branch"
})
}
}
}
}



@@ -0,0 +1,42 @@
/*
* 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 none
stages {
stage("foo") {
steps {
parallel("first one": {
echo "First branch"
},
"second one": {
echo "Second branch"
})
}
}
}
}



0 comments on commit fbfb5ab

Please sign in to comment.