Skip to content
Permalink
Browse files

[FIXED JENKINS-31386] Define the scm var in standalone projects using…

… CpsScmFlowDefinition.
  • Loading branch information
jglick committed Dec 4, 2015
1 parent 1602fca commit fe22dc9fa39267239e6ca16001bd9cd97b0ee48c
@@ -2,6 +2,10 @@

Only noting significant user changes, not internal code cleanups and minor bug fixes.

## 1.12 (upcoming)

* [JENKINS-31386](https://issues.jenkins-ci.org/browse/JENKINS-31386): `checkout scm` now works also in _Workflow script from SCM_ to better interoperate with multibranch projects.

## 1.12-beta-2 (Nov 25 2015)

* [JENKINS-29705](https://issues.jenkins-ci.org/browse/JENKINS-29705): added _Thread Dump_ link to running flow builds for diagnosing problems like hangs.
@@ -27,7 +27,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler">
<f:dropdownDescriptorSelector field="scm" title="SCM" descriptors="${descriptor.applicableDescriptors}"/>
<f:entry field="scriptPath" title="${%Script Path}">
<f:textbox default="flow.groovy"/>
<f:textbox default="Jenkinsfile"/>
</f:entry>
<st:include it="${descriptor.snippetizer}" page="block.jelly"/>
</j:jelly>
@@ -1,4 +1,6 @@
<div>
Relative location within the checkout of your Workflow script.
Note that it will always be run inside a Groovy sandbox.
<code>Jenkinsfile</code> is conventional and allows you to switch easily to a multibranch project
(just use <code>checkout scm</code> to retrieve sources from the same location as is configured here).
</div>
@@ -36,8 +36,11 @@
import jenkins.branch.Branch;
import jenkins.scm.api.SCMRevisionAction;
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.CpsScript;
import org.jenkinsci.plugins.workflow.cps.GlobalVariable;
import org.jenkinsci.plugins.workflow.flow.FlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.pickles.Pickle;
import org.jenkinsci.plugins.workflow.support.pickles.SingleTypedPickleFactory;
@@ -62,6 +65,13 @@
Job<?,?> job = build.getParent();
BranchJobProperty property = job.getProperty(BranchJobProperty.class);
if (property == null) {
if (job instanceof WorkflowJob) {
FlowDefinition defn = ((WorkflowJob) job).getDefinition();
if (defn instanceof CpsScmFlowDefinition) {
// JENKINS-31386: retrofit to work with standalone projects, minus the exact revision support.
return ((CpsScmFlowDefinition) defn).getScm();
}
}
throw new IllegalStateException("inappropriate context");
}
Branch branch = property.getBranch();
@@ -27,4 +27,7 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core">
Represents the SCM configuration in a multibranch project build.
Use <code>checkout scm</code> to check out sources matching <code>Jenkinsfile</code>.
<br/>You may also use this in a standalone project configured with <i>Workflow script from SCM</i>,
though in that case the checkout will just be of the latest revision in the branch,
possibly newer than the revision from which the Workflow script was loaded.
</j:jelly>
@@ -33,10 +33,12 @@
import jenkins.plugins.git.GitSCMSource;
import org.apache.commons.io.FileUtils;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.global.WorkflowLibRepository;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.scm.GitSampleRepoRule;
import org.jenkinsci.plugins.workflow.steps.scm.GitStep;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -121,4 +123,21 @@
});
}

@Issue("JENKINS-31386")
@Test public void standaloneProject() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
sampleGitRepo.init();
sampleGitRepo.write("Jenkinsfile", "node {checkout scm; echo readFile('file')}");
sampleGitRepo.write("file", "some content");
sampleGitRepo.git("add", "Jenkinsfile");
sampleGitRepo.git("commit", "--all", "--message=flow");
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsScmFlowDefinition(new GitStep(sampleGitRepo.toString()).createSCM(), "Jenkinsfile"));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("some content", b);
}
});
}

}

0 comments on commit fe22dc9

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