Skip to content

Commit 75930fc

Browse files
committed
Merge branch 'master' of github.com:jenkinsci/pipeline-model-definition-plugin into JENKINS-48523
2 parents 1dfa65c + 9cc0da1 commit 75930fc

File tree

26 files changed

+512
-56
lines changed

26 files changed

+512
-56
lines changed

Jenkinsfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pipeline {
1111

1212
// Set log rotation, timeout and timestamps in the console
1313
options {
14-
buildDiscarder(logRotator(numToKeepStr:'20'))
14+
buildDiscarder(logRotator(numToKeepStr:'10'))
1515
timestamps()
1616
timeout(time: 90, unit: 'MINUTES')
1717
}
@@ -30,7 +30,7 @@ pipeline {
3030
parallel {
3131
stage("linux") {
3232
agent {
33-
label "java"
33+
label "highmem"
3434
}
3535
steps {
3636
sh 'mvn clean install -Dmaven.test.failure.ignore=true'
@@ -66,7 +66,7 @@ pipeline {
6666
}
6767
stage("linux-newer-core") {
6868
agent {
69-
label "java"
69+
label "highmem"
7070
}
7171
steps {
7272
sh "mvn clean install -Dmaven.test.failure.ignore=true -Djava.level=8 -Djenkins.version=${NEWER_CORE_VERSION}"

pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTValue.java

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -115,47 +115,60 @@ public String toString() {
115115
}
116116

117117
public static ModelASTValue fromConstant(final Object o, Object sourceLocation) {
118-
return new ModelASTValue(sourceLocation, o) {
119-
@Override
120-
public boolean isLiteral() {
121-
return true;
122-
}
118+
return new ConstantValue(sourceLocation, o);
119+
}
120+
121+
public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
122+
return new GStringValue(sourceLocation, gstring);
123+
}
123124

124-
@Override
125-
public String toGroovy() {
126-
if (getValue() instanceof String) {
127-
String str = (String) getValue();
128-
str = str.replace("\\", "\\\\");
129-
if (str.indexOf('\n') == -1) {
130-
return "'" + (str.replace("'", "\\'")) + "'";
131-
} else {
132-
return "'''" + (str.replace("'", "\\'")) + "'''";
133-
}
134-
} else if (getValue() != null) {
135-
return getValue().toString();
125+
private static final class ConstantValue extends ModelASTValue {
126+
ConstantValue(Object sourceLocation, Object v) {
127+
super(sourceLocation, v);
128+
}
129+
130+
@Override
131+
public boolean isLiteral() {
132+
return true;
133+
}
134+
135+
@Override
136+
public String toGroovy() {
137+
if (getValue() instanceof String) {
138+
String str = (String) getValue();
139+
str = str.replace("\\", "\\\\");
140+
if (str.indexOf('\n') == -1) {
141+
return "'" + (str.replace("'", "\\'")) + "'";
136142
} else {
137-
return null;
143+
return "'''" + (str.replace("'", "\\'")) + "'''";
138144
}
145+
} else if (getValue() != null) {
146+
return getValue().toString();
147+
} else {
148+
return null;
139149
}
140-
};
150+
}
141151
}
142152

143-
public static ModelASTValue fromGString(final String gstring, Object sourceLocation) {
144-
return new ModelASTValue(sourceLocation, gstring) {
145-
@Override
146-
public boolean isLiteral() {
147-
return false;
148-
}
153+
private static final class GStringValue extends ModelASTValue {
154+
GStringValue(Object sourceLocation, Object v) {
155+
super(sourceLocation, v);
156+
}
149157

150-
@Override
151-
public String toGroovy() {
152-
String gstring = (String)getValue();
153-
if (gstring.startsWith("${") && gstring.endsWith("}")) {
154-
return gstring.substring(2, gstring.length() - 1);
155-
} else {
156-
return gstring;
157-
}
158+
@Override
159+
public boolean isLiteral() {
160+
return false;
161+
}
162+
163+
@Override
164+
public String toGroovy() {
165+
String gstring = (String)getValue();
166+
if (gstring.startsWith("${") && gstring.endsWith("}")) {
167+
return gstring.substring(2, gstring.length() - 1);
168+
} else {
169+
return gstring;
158170
}
159-
};
171+
}
172+
160173
}
161174
}

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Agent.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ package org.jenkinsci.plugins.pipeline.modeldefinition.model
2626
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings
2727
import groovy.transform.EqualsAndHashCode
2828
import groovy.transform.ToString
29+
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.AbstractDockerAgent
2930
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgent
3031
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.DeclarativeAgentDescriptor
3132
import org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.None
3233
import org.jenkinsci.plugins.pipeline.modeldefinition.options.DeclarativeOption
3334
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.CheckoutToSubdirectory
35+
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.ContainerPerStage
3436
import org.jenkinsci.plugins.pipeline.modeldefinition.options.impl.SkipDefaultCheckout
3537
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
3638
import org.jenkinsci.plugins.structs.SymbolLookup
@@ -102,6 +104,18 @@ class Agent extends MappedClosure<Object,Agent> implements Serializable {
102104
if (subdir?.subdirectory != null && subdir?.subdirectory != "") {
103105
a.setSubdirectory(subdir.subdirectory)
104106
}
107+
if (a instanceof AbstractDockerAgent) {
108+
ContainerPerStage containerPerStage = (ContainerPerStage) options.get("newContainerPerStage")
109+
if (containerPerStage != null) {
110+
if (context instanceof Root) {
111+
// If we're on the root, make sure we switch to basically just doing a label
112+
a.containerPerStageRoot = true
113+
} else if (context instanceof Stage && context.agent == null) {
114+
// While if we're on a stage that doesn't have an explicit agent, make sure we reuse the node
115+
a.reuseNode = true
116+
}
117+
}
118+
}
105119
}
106120
a.setDoCheckout(doCheckout)
107121

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Aborted.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
2929
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
3030
import org.jenkinsci.plugins.workflow.job.WorkflowRun
3131

32+
import javax.annotation.Nonnull
33+
3234
/**
3335
* A {@link BuildCondition} for matching aborted builds.
3436
*
@@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
3739
@Extension(ordinal=800d) @Symbol("aborted")
3840
class Aborted extends BuildCondition {
3941
@Override
40-
boolean meetsCondition(WorkflowRun r) {
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
4143
Result execResult = getExecutionResult(r)
4244
return execResult == Result.ABORTED || r.getResult() == Result.ABORTED
4345
}

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Always.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import org.jenkinsci.Symbol
2828
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
2929
import org.jenkinsci.plugins.workflow.job.WorkflowRun
3030

31+
import javax.annotation.Nonnull
32+
3133
/**
3234
* A {@link BuildCondition} for matching all builds regardless of status.
3335
*
@@ -36,7 +38,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
3638
@Extension(ordinal=1000d) @Symbol("always")
3739
class Always extends BuildCondition {
3840
@Override
39-
boolean meetsCondition(WorkflowRun r) {
41+
boolean meetsCondition(@Nonnull WorkflowRun r) {
4042
return true
4143
}
4244

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Changed.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
2929
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
3030
import org.jenkinsci.plugins.workflow.job.WorkflowRun
3131

32+
import javax.annotation.Nonnull
33+
3234
/**
3335
* A {@link BuildCondition} for matching builds with a different status than the previous build.
3436
*
@@ -37,14 +39,13 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
3739
@Extension(ordinal=900d) @Symbol("changed")
3840
class Changed extends BuildCondition {
3941
@Override
40-
boolean meetsCondition(WorkflowRun r) {
41-
Result execResult = getExecutionResult(r)
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
4243
// Only look at the previous completed build.
4344
WorkflowRun prev = r.getPreviousCompletedBuild()
4445

4546
// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
4647
// SUCCESS.
47-
Result runResult = execResult.combine(r.getResult() ?: Result.SUCCESS)
48+
Result runResult = combineResults(r)
4849

4950
// If there's no previous build, we're inherently changed.
5051
if (prev == null) {

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Failure.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
2929
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
3030
import org.jenkinsci.plugins.workflow.job.WorkflowRun
3131

32+
import javax.annotation.Nonnull
33+
3234
/**
3335
* A {@link BuildCondition} for matching failed builds.
3436
*
@@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
3739
@Extension(ordinal=700d) @Symbol("failure")
3840
class Failure extends BuildCondition {
3941
@Override
40-
boolean meetsCondition(WorkflowRun r) {
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
4143
Result execResult = getExecutionResult(r)
4244
return execResult == Result.FAILURE || r.getResult() == Result.FAILURE
4345
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2018, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.jenkinsci.plugins.pipeline.modeldefinition.model.conditions
25+
26+
import hudson.Extension
27+
import hudson.model.Result
28+
import org.jenkinsci.Symbol
29+
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
30+
import org.jenkinsci.plugins.workflow.job.WorkflowRun
31+
32+
import javax.annotation.Nonnull
33+
34+
/**
35+
* A {@link BuildCondition} for matching builds where the previous build was not SUCCESS but the current build is.
36+
*
37+
* @author Andrew Bayer
38+
*/
39+
@Extension(ordinal=890d) @Symbol("fixed")
40+
class Fixed extends BuildCondition {
41+
@Override
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
43+
// Only look at the previous completed build.
44+
WorkflowRun prev = r.getPreviousCompletedBuild()
45+
46+
// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
47+
// SUCCESS.
48+
Result runResult = combineResults(r)
49+
50+
// If there's no previous build, we can't exactly be fixed, can we?
51+
if (prev == null) {
52+
return false
53+
} else {
54+
return runResult == Result.SUCCESS && prev.getResult() in [Result.FAILURE, Result.UNSTABLE]
55+
}
56+
}
57+
58+
@Override
59+
String getDescription() {
60+
return Messages.Fixed_Description()
61+
}
62+
63+
64+
static final long serialVersionUID = 1L
65+
66+
}

pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/NotBuilt.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import org.jenkinsci.Symbol
2929
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
3030
import org.jenkinsci.plugins.workflow.job.WorkflowRun
3131

32+
import javax.annotation.Nonnull
33+
3234
/**
3335
* A {@link BuildCondition} for matching unbuilt builds, such as those stopped by milestones.
3436
*
@@ -37,7 +39,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
3739
@Extension(ordinal=400d) @Symbol("notBuilt")
3840
class NotBuilt extends BuildCondition {
3941
@Override
40-
boolean meetsCondition(WorkflowRun r) {
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
4143
Result execResult = getExecutionResult(r)
4244
return execResult == Result.NOT_BUILT || r.getResult() == Result.NOT_BUILT
4345
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2018, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.jenkinsci.plugins.pipeline.modeldefinition.model.conditions
25+
26+
import hudson.Extension
27+
import hudson.model.Result
28+
import org.jenkinsci.Symbol
29+
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition
30+
import org.jenkinsci.plugins.workflow.job.WorkflowRun
31+
32+
import javax.annotation.Nonnull
33+
34+
/**
35+
* A {@link BuildCondition} for matching builds where the previous build was better than the current build.
36+
*
37+
* @author Andrew Bayer
38+
*/
39+
@Extension(ordinal=880d) @Symbol("regression")
40+
class Regression extends BuildCondition {
41+
@Override
42+
boolean meetsCondition(@Nonnull WorkflowRun r) {
43+
// Only look at the previous completed build.
44+
WorkflowRun prev = r.getPreviousCompletedBuild()
45+
46+
// Get the *worst* result of either the execution or the run. If the run's result is null, that's effectively
47+
// SUCCESS.
48+
Result runResult = combineResults(r)
49+
50+
// If there's no previous build, we can't exactly be regressing, can we?
51+
if (prev == null) {
52+
return false
53+
} else {
54+
return runResult.isWorseThan(prev.getResult())
55+
}
56+
}
57+
58+
@Override
59+
String getDescription() {
60+
return Messages.Regression_Description()
61+
}
62+
63+
64+
static final long serialVersionUID = 1L
65+
66+
}

0 commit comments

Comments
 (0)