Skip to content
Permalink
Browse files

[FIXED JENKINS-46809] Add sequential groups of parallel stages

  • Loading branch information
abayer committed Apr 24, 2018
1 parent d778bbd commit 9511756ebf7dcc2dc2fc5ed286ef1ba11525b3e8
Showing with 2,048 additions and 123 deletions.
  1. +123 −50 ...ine-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStage.java
  2. +3 −0 pipeline-model-api/src/main/resources/ast-schema.json
  3. +33 −7 ...odel-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
  4. +7 −2 ...efinition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
  5. +11 −1 ...finition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
  6. +26 −2 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/RuntimeASTTransformer.groovy
  7. +23 −7 ...rc/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
  8. +2 −2 ...-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/Messages.properties
  9. +115 −48 ...inition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
  10. +11 −2 ...definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AbstractModelDefTest.java
  11. +10 −0 ...line-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/AgentTest.java
  12. +97 −0 ...el-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/BasicModelDefTest.java
  13. +50 −0 ...finition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/DeclarativeUpgradeTest.java
  14. +11 −0 ...odel-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/EnvironmentTest.java
  15. +21 −0 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/PostStageTest.java
  16. +16 −0 ...line-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ToolsTest.java
  17. +48 −1 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/ValidatorTest.java
  18. +10 −0 ...-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
  19. +10 −1 ...ion/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ExecuteConvertedTest.java
  20. +63 −0 pipeline-model-definition/src/test/resources/agentOnGroup.groovy
  21. +70 −0 pipeline-model-definition/src/test/resources/environmentInGroup.groovy
  22. +45 −0 pipeline-model-definition/src/test/resources/errors/emptyStagesInGroup.groovy
  23. +55 −0 pipeline-model-definition/src/test/resources/errors/parallelStagesAndGroups.groovy
  24. +61 −0 pipeline-model-definition/src/test/resources/errors/parallelStagesGroupsDeepNesting.groovy
  25. +58 −0 pipeline-model-definition/src/test/resources/errors/parallelStagesStepsAndGroups.groovy
  26. +46 −0 pipeline-model-definition/src/test/resources/errors/parallelStepsAndGroups.groovy
  27. +52 −0 pipeline-model-definition/src/test/resources/errors/topLevelStageGroupsDeepNesting.groovy
  28. +81 −0 pipeline-model-definition/src/test/resources/json/agentOnGroup.json
  29. +74 −0 pipeline-model-definition/src/test/resources/json/errors/parallelStagesAndGroups.json
  30. +82 −0 pipeline-model-definition/src/test/resources/json/errors/parallelStagesGroupsDeepNesting.json
  31. +53 −0 pipeline-model-definition/src/test/resources/json/errors/parallelStagesStepsAndGroups.json
  32. +53 −0 pipeline-model-definition/src/test/resources/json/errors/parallelStepsAndGroups.json
  33. +61 −0 pipeline-model-definition/src/test/resources/json/errors/topLevelStageGroupsDeepNesting.json
  34. +104 −0 pipeline-model-definition/src/test/resources/json/parallelStagesGroupsAndStages.json
  35. +40 −0 pipeline-model-definition/src/test/resources/json/topLevelStageGroup.json
  36. BIN ...pipeline/modeldefinition/DeclarativeUpgradeTest/parallelAddsGroupsExecutionModelActionUpgrade.zip
  37. +76 −0 pipeline-model-definition/src/test/resources/parallelStagesGroupsAndStages.groovy
  38. +88 −0 pipeline-model-definition/src/test/resources/postStage/groupLocalAll.groovy
  39. +72 −0 pipeline-model-definition/src/test/resources/postStage/postInParallelAndSequential.groovy
  40. +76 −0 pipeline-model-definition/src/test/resources/toolsInGroup.groovy
  41. +46 −0 pipeline-model-definition/src/test/resources/topLevelStageGroup.groovy
  42. +65 −0 pipeline-model-definition/src/test/resources/when/simpleGroupWhen.groovy
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.pipeline.modeldefinition.ast;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONArray;
@@ -17,40 +18,43 @@
* @see ModelASTPipelineDef
*/
public final class ModelASTStage extends ModelASTElement {
private String name;
private ModelASTAgent agent;
protected String name;
protected ModelASTAgent agent;
protected ModelASTPostStage post;
protected ModelASTWhen when;
protected ModelASTTools tools;
protected ModelASTEnvironment environment;
private ModelASTStages stages;
private List<ModelASTBranch> branches = new ArrayList<>();
private ModelASTPostStage post;
private ModelASTWhen when;
private ModelASTTools tools;
private ModelASTEnvironment environment;
private Boolean failFast;
private ModelASTStages parallel;
private ModelASTOptions options;
private ModelASTStageInput input;

@Deprecated
private transient ModelASTStages parallel;
private List<ModelASTStage> parallelContent = new ArrayList<>();

public ModelASTStage(Object sourceLocation) {
super(sourceLocation);
}

protected Object readResolve() throws IOException {
// If there's already a set of parallel stages defined, add that to the parallel content instead.
if (this.parallel != null) {
if (this.parallelContent == null) {
this.parallelContent = new ArrayList<>();
}
this.parallelContent.addAll(this.parallel.getStages());
this.parallel = null;
}
return this;
}

@Override
public JSONObject toJSON() {
JSONObject o = new JSONObject();
o.accumulate("name", name);

if (branches.isEmpty() && parallel != null) {
o.accumulate("parallel", parallel.toJSON());
} else {
final JSONArray a = new JSONArray();
for (ModelASTBranch branch : branches) {
a.add(branch.toJSON());
}
o.accumulate("branches", a);
}

if (failFast != null) {
o.accumulate("failFast", failFast);
}
if (agent != null) {
o.accumulate("agent", agent.toJSON());
}
@@ -75,6 +79,28 @@ public JSONObject toJSON() {
if (input != null) {
o.accumulate("input", input.toJSON());
}
if (stages != null) {
o.accumulate("stages", stages.toJSON());
}
if (branches.isEmpty()) {
if (!parallelContent.isEmpty()) {
final JSONArray a = new JSONArray();
for (ModelASTStage content : parallelContent) {
a.add(content.toJSON());
}
o.accumulate("parallel", a);
}
} else {
final JSONArray a = new JSONArray();
for (ModelASTBranch branch : branches) {
a.add(branch.toJSON());
}
o.accumulate("branches", a);
}

if (failFast != null) {
o.accumulate("failFast", failFast);
}

return o;
}
@@ -86,12 +112,7 @@ public void validate(@Nonnull final ModelValidator validator) {

public void validate(final ModelValidator validator, boolean isNested) {
validator.validateElement(this, isNested);
for (ModelASTBranch branch : branches) {
branch.validate(validator);
}
if (parallel != null) {
parallel.validate(validator, true);
}

if (agent != null) {
agent.validate(validator);
}
@@ -113,6 +134,15 @@ public void validate(final ModelValidator validator, boolean isNested) {
if (input != null) {
input.validate(validator);
}
if (stages != null) {
stages.validate(validator, true);
}
for (ModelASTBranch branch : branches) {
branch.validate(validator);
}
for (ModelASTStage content: parallelContent) {
content.validate(validator, true);
}
}

@Override
@@ -138,13 +168,25 @@ public String toGroovy() {
if (input != null) {
result.append(input.toGroovy());
}
if (branches.isEmpty() && parallel != null) {
if (post != null) {
result.append(post.toGroovy());
}
if (stages != null) {
result.append("stages {\n");
result.append(stages.toGroovy());
result.append("}\n");
}
if (branches.isEmpty()) {
if (failFast != null && failFast) {
result.append("failFast true\n");
}
result.append("parallel {\n");
result.append(parallel.toGroovy());
result.append("}\n");
if (!parallelContent.isEmpty()) {
result.append("parallel {\n");
for (ModelASTStage content : parallelContent) {
result.append(content.toGroovy());
}
result.append("}\n");
}
} else {
result.append("steps {\n");
if (branches.size() > 1) {
@@ -173,10 +215,6 @@ public String toGroovy() {
result.append("}\n");
}

if (post != null) {
result.append(post.toGroovy());
}

result.append("}\n");

return result.toString();
@@ -185,15 +223,9 @@ public String toGroovy() {
@Override
public void removeSourceLocation() {
super.removeSourceLocation();
for (ModelASTBranch branch: branches) {
branch.removeSourceLocation();
}
if (agent != null) {
agent.removeSourceLocation();
}
if (parallel != null) {
parallel.removeSourceLocation();
}
if (when != null) {
when.removeSourceLocation();
}
@@ -212,6 +244,18 @@ public void removeSourceLocation() {
if (input != null) {
input.removeSourceLocation();
}
if (stages != null) {
stages.removeSourceLocation();
}
for (ModelASTBranch branch: branches) {
branch.removeSourceLocation();
}
if (parallel != null) {
parallel.removeSourceLocation();
}
for (ModelASTStage content : parallelContent) {
content.removeSourceLocation();
}
}

public String getName() {
@@ -230,14 +274,6 @@ public void setAgent(ModelASTAgent agent) {
this.agent = agent;
}

public List<ModelASTBranch> getBranches() {
return branches;
}

public void setBranches(List<ModelASTBranch> branches) {
this.branches = branches;
}

public ModelASTPostStage getPost() {
return post;
}
@@ -270,6 +306,22 @@ public void setEnvironment(ModelASTEnvironment environment) {
this.environment = environment;
}

public ModelASTStages getStages() {
return stages;
}

public void setStages(ModelASTStages stages) {
this.stages = stages;
}

public List<ModelASTBranch> getBranches() {
return branches;
}

public void setBranches(List<ModelASTBranch> branches) {
this.branches = branches;
}

public Boolean getFailFast() {
return failFast;
}
@@ -278,10 +330,12 @@ public void setFailFast(Boolean f) {
this.failFast = f;
}

@Deprecated
public ModelASTStages getParallel() {
return parallel;
}

@Deprecated
public void setParallel(ModelASTStages s) {
this.parallel = s;
}
@@ -302,20 +356,30 @@ public void setInput(ModelASTStageInput input) {
this.input = input;
}

public List<ModelASTStage> getParallelContent() {
return parallelContent;
}

public void setParallelContent(List<ModelASTStage> parallelContent) {
this.parallelContent = parallelContent;
}

@Override
public String toString() {
return "ModelASTStage{" +
"name='" + name + '\'' +
", agent=" + agent +
", when=" + when +
", branches=" + branches +
", post=" + post +
", tools=" + tools +
", environment=" + environment +
", stages=" + stages +
", branches=" + branches +
", failFast=" + failFast +
", parallel=" + parallel +
", options=" + options +
", input=" + input +
", parallelContent=" + parallelContent +
"}";
}

@@ -357,12 +421,19 @@ public boolean equals(Object o) {
if (getInput() != null ? !getInput().equals(that.getInput()) : that.getInput() != null) {
return false;
}
if (getStages() != null ? !getStages().equals(that.getStages()) : that.getStages() != null) {
return false;
}
if (getFailFast() != null ? !getFailFast().equals(that.getFailFast()) : that.getFailFast() != null) {
return false;
}
if (getParallel() != null ? !getParallel().equals(that.getParallel()) : that.getParallel() != null) {
return false;
}
if (getParallelContent() != null ? !getParallelContent().equals(that.getParallelContent())
: that.getParallelContent() != null) {
return false;
}
return getBranches() != null ? getBranches().equals(that.getBranches()) : that.getBranches() == null;

}
@@ -372,15 +443,17 @@ public int hashCode() {
int result = super.hashCode();
result = 31 * result + (getName() != null ? getName().hashCode() : 0);
result = 31 * result + (getAgent() != null ? getAgent().hashCode() : 0);
result = 31 * result + (getBranches() != null ? getBranches().hashCode() : 0);
result = 31 * result + (getWhen() != null ? getWhen().hashCode() : 0);
result = 31 * result + (getPost() != null ? getPost().hashCode() : 0);
result = 31 * result + (getTools() != null ? getTools().hashCode() : 0);
result = 31 * result + (getEnvironment() != null ? getEnvironment().hashCode() : 0);
result = 31 * result + (getStages() != null ? getStages().hashCode() : 0);
result = 31 * result + (getBranches() != null ? getBranches().hashCode() : 0);
result = 31 * result + (getFailFast() != null ? getFailFast().hashCode() : 0);
result = 31 * result + (getParallel() != null ? getParallel().hashCode() : 0);
result = 31 * result + (getOptions() != null ? getOptions().hashCode() : 0);
result = 31 * result + (getInput() != null ? getInput().hashCode() : 0);
result = 31 * result + (getParallelContent() != null ? getParallelContent().hashCode() : 0);
return result;
}
}
@@ -519,6 +519,9 @@
},
"parallel": {
"$ref": "#/definitions/stages"
},
"stages": {
"$ref": "#/definitions/stages"
}
},
"required": [

0 comments on commit 9511756

Please sign in to comment.
You can’t perform that action at this time.