Skip to content

Commit

Permalink
Followup to JENKINS-41900 - just record if in stage
Browse files Browse the repository at this point in the history
There's no actual good reason for carrying the whole context (i.e.,
Root or Stage object) around in the DeclarativeAgent when all we need
to know is whether we're already in a stage. So...switch that to a
boolean and have Agent.groovy check whether the context it's handed is
a Root instance. If it is a Root instance, we're not in a stage. If it
isn't a Root instance, we are in a stage. Tada.
  • Loading branch information
abayer committed Feb 16, 2017
1 parent ad6afe6 commit 5e21e52
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Expand Up @@ -35,15 +35,15 @@
* @author Andrew Bayer
*/
public abstract class DeclarativeAgent<A extends DeclarativeAgent<A>> extends WithScriptDescribable<A> implements ExtensionPoint {
protected Object context;
protected boolean inStage;
protected boolean doCheckout;

public void setContext(Object context) {
this.context = context;
public void setInStage(boolean inStage) {
this.inStage = inStage;
}

public Object getContext() {
return context;
public boolean isInStage() {
return inStage;
}

public void setDoCheckout(boolean doCheckout) {
Expand Down
Expand Up @@ -71,7 +71,11 @@ public class Agent extends MappedClosure<Object,Agent> implements Serializable {

DeclarativeAgent a = DeclarativeAgentDescriptor.instanceForDescriptor(foundDescriptor, argMap)
boolean doCheckout = false
a.setContext(context)
if (context instanceof Root) {
a.setInStage(false)
} else {
a.setInStage(true)
}
if (root != null) {
SkipDefaultCheckout skip = (SkipDefaultCheckout) root?.options?.options?.get("skipDefaultCheckout")
if (!skip?.isSkipDefaultCheckout()) {
Expand Down
Expand Up @@ -46,7 +46,7 @@ public class LabelScript extends DeclarativeAgentScript<Label> {
try {
script.node(describable?.label) {
if (describable.isDoCheckout() && describable.hasScmContext(script)) {
if (describable.context instanceof Root) {
if (!describable.inStage) {
script.stage(SyntheticStageNames.checkout()) {
script.checkout script.scm
}
Expand Down

0 comments on commit 5e21e52

Please sign in to comment.