-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-26100] Return a map of SCM-contributed variables #16
Changes from 4 commits
cf36f5b
a87bd69
39a28c8
bec924c
dbcfe52
d99b76f
ef96e96
da9e682
eb9296e
f5a2dac
65952d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
<parent> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>plugin</artifactId> | ||
<version>2.23</version> | ||
<version>2.27</version> | ||
<relativePath /> | ||
</parent> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
|
@@ -38,17 +38,19 @@ | |
</pluginRepository> | ||
</pluginRepositories> | ||
<properties> | ||
<jenkins.version>1.642.3</jenkins.version> | ||
<jenkins-core.version>2.58-20170502.192524-8</jenkins-core.version> <!-- TODO: Switch to release once https://github.com/jenkinsci/jenkins/pull/2730 is merged and released --> | ||
<jenkins-war.version>2.58-20170502.192544-8</jenkins-war.version> <!-- TODO: Switch to release once https://github.com/jenkinsci/jenkins/pull/2730 is merged and released --> | ||
<java.level>8</java.level> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🐛 Hard dependency on Jenkins 2.60 and JDK 8 means we can no longer bundle this version in Blue Ocean's aggregator :( Are the minimums here a necessary change? Somewhat concerned about this as the Blue Ocean ATH won't be run with all the latest Pipeline goodness. From this point onwards we have lost end to end tests for this plugin as well as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this was required. The underlying change in core didn't go in until 2.60. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shrug This required a change in core to work, so... |
||
<no-test-jar>false</no-test-jar> | ||
<scm-api-plugin.version>2.0.8</scm-api-plugin.version> | ||
<git-plugin.version>3.1.0</git-plugin.version> | ||
<subversion-plugin.version>2.7.2</subversion-plugin.version> | ||
<scm-api-plugin.version>2.1.1</scm-api-plugin.version> | ||
<git-plugin.version>3.3.1-20170503.162551-3</git-plugin.version> <!-- TODO: Switch to release once https://github.com/jenkinsci/git-plugin/pull/492 is merged and released --> | ||
<subversion-plugin.version>2.7.3-20170505.145345-1</subversion-plugin.version> <!-- TODO: Switch to release once https://github.com/jenkinsci/subversion-plugin/pull/182 is merged and released --> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>workflow-step-api</artifactId> | ||
<version>1.15</version> | ||
<version>2.9</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
|
@@ -104,38 +106,50 @@ | |
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-step-api</artifactId> | ||
<version>1.15</version> | ||
<version>2.9</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-cps</artifactId> | ||
<version>1.15</version> | ||
<version>2.29</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-multibranch</artifactId> | ||
<version>2.14</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>cloudbees-folder</artifactId> | ||
<version>5.18</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-job</artifactId> | ||
<version>1.15</version> | ||
<version>2.10</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you not need 2.12? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope - this is dependent on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you not need to have an integration test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, you do—it just does not depend on |
||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-basic-steps</artifactId> | ||
<version>1.15</version> | ||
<version>2.4</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-durable-task-step</artifactId> | ||
<version>1.15</version> | ||
<version>2.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.plugins.workflow</groupId> | ||
<artifactId>workflow-support</artifactId> | ||
<version>1.15</version> | ||
<version>2.14</version> | ||
<classifier>tests</classifier> | ||
<scope>test</scope> | ||
</dependency> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, 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. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.steps.scm; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import hudson.EnvVars; | ||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.Launcher; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.model.listeners.SCMListener; | ||
import hudson.scm.SCM; | ||
import hudson.scm.SCMRevisionState; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl; | ||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution; | ||
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback; | ||
import org.jenkinsci.plugins.workflow.steps.EnvironmentExpander; | ||
import org.jenkinsci.plugins.workflow.steps.Step; | ||
import org.jenkinsci.plugins.workflow.steps.StepContext; | ||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; | ||
import org.jenkinsci.plugins.workflow.steps.StepDescriptor; | ||
import org.jenkinsci.plugins.workflow.steps.StepExecution; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import javax.annotation.Nonnull; | ||
import javax.inject.Inject; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
|
||
/** | ||
* A step which checks out some kind of {@link SCM}, and then runs a body with any environment variables contributed | ||
* by the {@link SCM} added to the environment. | ||
*/ | ||
public class WithCheckoutStep extends Step implements Serializable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can do without this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okiedokie, will remove. |
||
|
||
private boolean poll = true; | ||
private boolean changelog = true; | ||
private final SCM scm; | ||
|
||
public boolean isPoll() { | ||
return poll; | ||
} | ||
|
||
@DataBoundSetter public void setPoll(boolean poll) { | ||
this.poll = poll; | ||
} | ||
|
||
public boolean isChangelog() { | ||
return changelog; | ||
} | ||
|
||
@DataBoundSetter public void setChangelog(boolean changelog) { | ||
this.changelog = changelog; | ||
} | ||
|
||
public SCM getScm() { | ||
return scm; | ||
} | ||
|
||
@DataBoundConstructor | ||
public WithCheckoutStep(SCM s) { | ||
this.scm = s; | ||
} | ||
|
||
@Override | ||
public StepExecution start(StepContext context) throws Exception { | ||
return new StepExecutionImpl(this, context); | ||
} | ||
|
||
|
||
public final void checkout(Run<?,?> run, FilePath workspace, TaskListener listener, Launcher launcher) throws Exception { | ||
SCMStep.doCheckout(getScm(), isChangelog(), isPoll(), run, workspace, listener, launcher); | ||
} | ||
|
||
public static final class StepExecutionImpl extends StepExecution implements Serializable{ | ||
|
||
private final WithCheckoutStep step; | ||
|
||
public StepExecutionImpl(WithCheckoutStep step, StepContext context) { | ||
super(context); | ||
this.step = step; | ||
} | ||
|
||
@Override | ||
public boolean start() throws Exception { | ||
Run<?, ?> run = getContext().get(Run.class); | ||
TaskListener listener = getContext().get(TaskListener.class); | ||
FilePath workspace = getContext().get(FilePath.class); | ||
Launcher launcher = getContext().get(Launcher.class); | ||
|
||
step.checkout(run, workspace, listener, launcher); | ||
Map<String,String> envVars = new TreeMap<>(); | ||
step.scm.buildEnvironment(run, envVars); | ||
|
||
getContext().newBodyInvoker(). | ||
withContext(EnvironmentExpander.merge(getContext().get(EnvironmentExpander.class), new ExpanderImpl(envVars))). | ||
withCallback(BodyExecutionCallback.wrap(getContext())). | ||
start(); | ||
|
||
return false; | ||
} | ||
|
||
@Override public void stop(Throwable cause) throws Exception { | ||
// should be no need to do anything special (but verify in JENKINS-26148) | ||
} | ||
|
||
@Override public void onResume() {} | ||
|
||
private static final long serialVersionUID = 1L; | ||
} | ||
|
||
private static final class ExpanderImpl extends EnvironmentExpander { | ||
private static final long serialVersionUID = 1; | ||
private final Map<String,String> overrides; | ||
private ExpanderImpl(Map<String,String> overrides) { | ||
this.overrides = new HashMap<>(); | ||
this.overrides.putAll(overrides); | ||
} | ||
|
||
@Override public void expand(@Nonnull EnvVars env) throws IOException, InterruptedException { | ||
env.overrideAll(overrides); | ||
} | ||
} | ||
|
||
@Extension | ||
public static class WithCheckoutStepDescriptor extends StepDescriptor { | ||
@Override | ||
public String getFunctionName() { | ||
return "withCheckout"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Checkout SCM with environment"; | ||
} | ||
|
||
@Override | ||
public boolean takesImplicitBlockArgument() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Set<? extends Class<?>> getRequiredContext() { | ||
return ImmutableSet.of(Run.class, FilePath.class, TaskListener.class, Launcher.class); | ||
} | ||
} | ||
|
||
private static final long serialVersionUID = 1L; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ The MIT License | ||
~ | ||
~ Copyright (c) 2017, 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. | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:f="/lib/form"> | ||
<f:dropdownDescriptorSelector field="scm" title="SCM" descriptors="${descriptor.applicableDescriptors}"/> | ||
<st:include page="config-generic.jelly" class="org.jenkinsci.plugins.workflow.steps.scm.SCMStep"/> | ||
</j:jelly> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.61
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.60 I meant.