Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #34 from jonsten/JENKINS-40255
[JENKINS-40255] Changed getSCMs(), now it checks for successful builds first.
  • Loading branch information
jglick committed Feb 10, 2017
2 parents c2bb083 + 2544212 commit c21b9ba
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Expand Up @@ -545,7 +545,10 @@ public void replaceAction(Action a) {
}

@Override public Collection<? extends SCM> getSCMs() {
WorkflowRun b = getLastCompletedBuild();
WorkflowRun b = getLastSuccessfulBuild();
if (b == null) {
b = getLastCompletedBuild();
}
if (b == null) {
return Collections.emptySet();
}
Expand Down
@@ -0,0 +1,42 @@
package org.jenkinsci.plugins.workflow.job;


import hudson.model.Result;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class WorkflowJobTest {
@Rule public JenkinsRule j = new JenkinsRule();

@Issue("JENKINS-40255")
@Test public void getSCM() throws Exception {
WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node {\n" +
" checkout(new hudson.scm.NullSCM())\n" +
"}"));
assertTrue("No runs has been performed and there should be no SCMs", p.getSCMs().isEmpty());

j.buildAndAssertSuccess(p);

assertEquals("Expecting one SCM", 1, p.getSCMs().size());

p.setDefinition(new CpsFlowDefinition("error 'Fail!'"));

j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));

assertEquals("Expecting one SCM even though last run failed",1, p.getSCMs().size());

p.setDefinition(new CpsFlowDefinition("echo 'Pass!'"));

j.buildAndAssertSuccess(p);

assertEquals("Expecting zero SCMs",0, p.getSCMs().size());
}
}

0 comments on commit c21b9ba

Please sign in to comment.