Skip to content

Commit

Permalink
Merge pull request #117 from abayer/switch-agent-context-logic
Browse files Browse the repository at this point in the history
Followup to JENKINS-41900 - just record if in stage
  • Loading branch information
abayer committed Feb 21, 2017
2 parents afaea38 + 2611c3a commit 20f8126
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 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 abstract class AbstractDockerPipelineScript<A extends AbstractDockerAgent
} else {
String targetLabel = DeclarativeDockerUtils.getLabel(describable.label)
Label l = (Label) Label.DescriptorImpl.instanceForName("label", [label: targetLabel])
l.context = describable.context
l.inStage = describable.inStage
l.doCheckout = describable.doCheckout
LabelScript labelScript = (LabelScript) l.getScript(script)
return labelScript.run {
Expand Down
Expand Up @@ -37,7 +37,7 @@ public class AnyScript extends DeclarativeAgentScript<Any> {
@Override
public Closure run(Closure body) {
Label l = (Label) Label.DescriptorImpl.instanceForName("label", [label: null])
l.context = describable.context
l.inStage = describable.inStage
l.doCheckout = describable.doCheckout
LabelScript labelScript = (LabelScript) l.getScript(script)
return labelScript.run {
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
Expand Up @@ -39,7 +39,7 @@ public class LabelAndOtherFieldAgentScript extends DeclarativeAgentScript<LabelA
script.echo "Running in labelAndOtherField with otherField = ${describable.getOtherField()}"
script.echo "And nested: ${describable.getNested()}"
Label l = (Label) Label.DescriptorImpl.instanceForName("label", [label: describable.label])
l.context = describable.context
l.inStage = describable.inStage
l.doCheckout = describable.doCheckout
LabelScript labelScript = (LabelScript) l.getScript(script)
return labelScript.run {
Expand Down

0 comments on commit 20f8126

Please sign in to comment.