Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #27 from abayer/jenkins-37219-test
[JENKINS-37219] Test for new overrideIndexTriggers job property.
  • Loading branch information
abayer committed Aug 28, 2016
2 parents b6d7978 + 0e1105a commit 80120a5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -84,7 +84,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>1.10</version>
<version>1.11-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -42,6 +42,7 @@
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.branch.OverrideIndexTriggersJobProperty;
import jenkins.model.BuildDiscarder;
import jenkins.model.BuildDiscarderProperty;
import jenkins.plugins.git.GitSCMSource;
Expand All @@ -51,6 +52,7 @@
import jenkins.scm.api.SCMSource;
import org.jenkinsci.plugins.scriptsecurity.scripts.ScriptApproval;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.SnippetizerTester;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty;
Expand Down Expand Up @@ -333,6 +335,62 @@ public void noPropertiesWarnings() throws Exception {
r.assertLogNotContains(Messages.JobPropertyStep__removed_property_warning(propName), b2);
}

@Issue("JENKINS-37219")
@Test public void disableTriggers() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "properties([overrideIndexTriggers(false)])");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--message=init");

WorkflowMultiBranchProject p = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
BranchSource branchSource = new BranchSource(new GitSCMSource("source-id", sampleRepo.toString(), "", "*", "", false));
p.getSourcesList().add(branchSource);

// Should be initial build of master, which sets the job property.
WorkflowJob master = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "master");
r.waitUntilNoActivity();
r.assertBuildStatusSuccess(master.getBuildByNumber(1));
assertEquals(2, master.getNextBuildNumber());

assertNotNull(master.getProperty(OverrideIndexTriggersJobProperty.class));
assertFalse(master.getProperty(OverrideIndexTriggersJobProperty.class).getEnableTriggers());

sampleRepo.write("Jenkinsfile", "properties([])");
sampleRepo.git("commit", "--all", "--message=master-2");
sampleRepo.notifyCommit(r);

WorkflowMultiBranchProjectTest.showIndexing(p);
// Should not be a new build.
assertEquals(2, master.getNextBuildNumber());

// Should be able to manually build master, which should result in the blocking going away.
WorkflowRun secondBuild = r.assertBuildStatusSuccess(master.scheduleBuild2(0));
assertNotNull(secondBuild);
assertEquals(2, secondBuild.getNumber());
assertEquals(3, master.getNextBuildNumber());
assertNull(master.getProperty(OverrideIndexTriggersJobProperty.class));


// Now let's see it actually trigger another build from a new commit.
sampleRepo.write("Jenkinsfile", "// yet more");
sampleRepo.git("commit", "--all", "--message=master-3");
sampleRepo.notifyCommit(r);
WorkflowMultiBranchProjectTest.showIndexing(p);
assertEquals(4, master.getNextBuildNumber());
}

@Issue("JENKINS-37219")
@Test
public void snippetGeneratorOverrideIndexing() throws Exception {
String snippetJson = "{'propertiesMap':\n" +
"{'stapler-class-bag': 'true', 'jenkins-branch-OverrideIndexTriggersJobProperty': \n" +
"{'specified': true, 'enableTriggers': true}},\n" +
"'stapler-class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep',\n" +
"'$class': 'org.jenkinsci.plugins.workflow.multibranch.JobPropertyStep'}";

new SnippetizerTester(r).assertGenerateSnippet(snippetJson, "properties [overrideIndexTriggers(true)]", null);
}

private <T extends Trigger> T getTriggerFromList(Class<T> clazz, List<Trigger<?>> triggers) {
for (Trigger t : triggers) {
if (clazz.isInstance(t)) {
Expand Down

0 comments on commit 80120a5

Please sign in to comment.