Skip to content

Commit

Permalink
[JENKINS-37219] Test for new overrideIndexTriggers job property.
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Aug 17, 2016
1 parent 281e8b2 commit 91acfa5
Show file tree
Hide file tree
Showing 2 changed files with 48 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 Down Expand Up @@ -333,6 +334,52 @@ 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.git("checkout", "master");
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.git("checkout", "master");
sampleRepo.write("Jenkinsfile", "// yet more");
sampleRepo.git("commit", "--all", "--message=master-3");
sampleRepo.notifyCommit(r);
WorkflowMultiBranchProjectTest.showIndexing(p);
assertEquals(4, master.getNextBuildNumber());
}

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 91acfa5

Please sign in to comment.