Skip to content
Permalink
Browse files
Merge pull request #12 from jglick/update-no-trigger-JENKINS-32396-JE…
…NKINS-30206

[JENKINS-30206] [JENKINS-32396] Honor changes to NoTriggerBranchProperty
  • Loading branch information
jglick committed Jun 1, 2016
2 parents eb538b8 + 4e19910 commit 5574409ef9334fb1774137627fe73f60174da515
@@ -84,12 +84,12 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>branch-api</artifactId>
<version>1.1</version>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.8</version>
<version>5.10</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
@@ -59,7 +59,7 @@
try {
if (property == null) {
project.addProperty(new BranchJobProperty(branch));
} else if (!property.getBranch().equals(branch)) {
} else { // TODO may add equality check if https://github.com/jenkinsci/branch-api-plugin/pull/36 or equivalent is implemented
property.setBranch(branch);
project.save();
}
@@ -93,7 +93,6 @@
assertEquals(3, lr.getArtifactNumToKeep());
}

@Issue("JENKINS-30206")
@Test public void useParameter() throws Exception {
sampleRepo.init();
ScriptApproval.get().approveSignature("method groovy.lang.Binding hasVariable java.lang.String"); // TODO add to generic whitelist
@@ -0,0 +1,171 @@
/*
* The MIT License
*
* Copyright 2016 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.multibranch;

import hudson.model.queue.QueueTaskFuture;
import java.util.Collections;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchSource;
import jenkins.branch.NamedExceptionsBranchPropertyStrategy;
import jenkins.branch.NoTriggerBranchProperty;
import jenkins.branch.NoTriggerOrganizationFolderProperty;
import jenkins.branch.OrganizationFolder;
import jenkins.plugins.git.GitSCMSource;
import jenkins.scm.api.SCMSource;
import jenkins.scm.impl.SingleSCMNavigator;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.steps.scm.GitSampleRepoRule;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

/**
* Integration test for {@link NoTriggerBranchProperty} and {@link NoTriggerOrganizationFolderProperty}.
*/
@Issue("JENKINS-32396")
public class NoTriggerBranchPropertyWorkflowTest {

@Rule public JenkinsRule r = new JenkinsRule();
@Rule public GitSampleRepoRule sampleRepo = new GitSampleRepoRule();

@Issue("JENKINS-30206")
@Test public void singleRepo() throws Exception {
round1();
WorkflowMultiBranchProject p = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
BranchSource branchSource = new BranchSource(new GitSCMSource("source-id", sampleRepo.toString(), "", "*", "", false));
branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] {
new NamedExceptionsBranchPropertyStrategy.Named("release*", new BranchProperty[] {new NoTriggerBranchProperty()})
}));
p.getSourcesList().add(branchSource);
// Should be initial builds of master & newfeature but not release.
WorkflowJob master = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "master");
r.waitUntilNoActivity();
assertEquals(2, master.getNextBuildNumber());
WorkflowJob release = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "release");
assertEquals(1, release.getNextBuildNumber());
WorkflowJob newfeature = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "newfeature");
assertEquals(2, newfeature.getNextBuildNumber());
round2();
WorkflowMultiBranchProjectTest.showIndexing(p);
// Should be second builds of master & newfeature but not release.
assertEquals(3, master.getNextBuildNumber());
assertEquals(1, release.getNextBuildNumber());
assertEquals(3, newfeature.getNextBuildNumber());
// Should be able to manually build release.
QueueTaskFuture<WorkflowRun> releaseBuild = release.scheduleBuild2(0);
assertNotNull(releaseBuild);
assertEquals(1, releaseBuild.get().getNumber());
assertEquals(2, release.getNextBuildNumber());
// Updating configuration should take effect for next time: new builds of newfeature & release but not master.
branchSource = new BranchSource(new GitSCMSource("source-id", sampleRepo.toString(), "", "*", "", false));
branchSource.setStrategy(new NamedExceptionsBranchPropertyStrategy(new BranchProperty[0], new NamedExceptionsBranchPropertyStrategy.Named[] {
new NamedExceptionsBranchPropertyStrategy.Named("master", new BranchProperty[] {new NoTriggerBranchProperty()})
}));
p.getSourcesList().clear();
p.getSourcesList().add(branchSource);
round3();
WorkflowMultiBranchProjectTest.showIndexing(p);
assertEquals(3, master.getNextBuildNumber());
assertEquals(3, release.getNextBuildNumber());
assertEquals(4, newfeature.getNextBuildNumber());
}

@Test public void organizationFolder() throws Exception {
round1();
OrganizationFolder top = r.jenkins.createProject(OrganizationFolder.class, "top");
top.getProperties().add(new NoTriggerOrganizationFolderProperty("(?!release.*).*"));
top.getNavigators().add(new SingleSCMNavigator("p", Collections.<SCMSource>singletonList(new GitSCMSource("source-id", sampleRepo.toString(), "", "*", "", false))));
top.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
top.getComputation().writeWholeLogTo(System.out);
WorkflowMultiBranchProject p = r.jenkins.getItemByFullName("top/p", WorkflowMultiBranchProject.class);
assertNotNull(p);
WorkflowJob master = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "master");
r.waitUntilNoActivity();
assertEquals(2, master.getNextBuildNumber());
WorkflowJob release = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "release");
assertEquals(1, release.getNextBuildNumber());
WorkflowJob newfeature = WorkflowMultiBranchProjectTest.scheduleAndFindBranchProject(p, "newfeature");
assertEquals(2, newfeature.getNextBuildNumber());
round2();
WorkflowMultiBranchProjectTest.showIndexing(p);
assertEquals(3, master.getNextBuildNumber());
assertEquals(1, release.getNextBuildNumber());
assertEquals(3, newfeature.getNextBuildNumber());
QueueTaskFuture<WorkflowRun> releaseBuild = release.scheduleBuild2(0);
assertNotNull(releaseBuild);
assertEquals(1, releaseBuild.get().getNumber());
assertEquals(2, release.getNextBuildNumber());
top.getProperties().replace(new NoTriggerOrganizationFolderProperty("(?!master$).*"));
round3();
WorkflowMultiBranchProjectTest.showIndexing(p);
assertEquals(3, master.getNextBuildNumber());
assertEquals(3, release.getNextBuildNumber());
assertEquals(4, newfeature.getNextBuildNumber());
}

private void round1() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--message=init");
sampleRepo.git("checkout", "-b", "newfeature");
sampleRepo.write("Jenkinsfile", "// newfeature");
sampleRepo.git("commit", "--all", "--message=newfeature");
sampleRepo.git("checkout", "-b", "release", "master");
sampleRepo.write("Jenkinsfile", "// release");
sampleRepo.git("commit", "--all", "--message=release");
}

private void round2() throws Exception {
sampleRepo.git("checkout", "master");
sampleRepo.write("Jenkinsfile", "// more");
sampleRepo.git("commit", "--all", "--message=master-2");
sampleRepo.git("checkout", "newfeature");
sampleRepo.write("Jenkinsfile", "// more");
sampleRepo.git("commit", "--all", "--message=newfeature-2");
sampleRepo.git("checkout", "release");
sampleRepo.write("Jenkinsfile", "// more");
sampleRepo.git("commit", "--all", "--message=release-2");
sampleRepo.notifyCommit(r);
}

private void round3() throws Exception {
sampleRepo.git("checkout", "master");
sampleRepo.write("Jenkinsfile", "// yet more");
sampleRepo.git("commit", "--all", "--message=master-3");
sampleRepo.git("checkout", "newfeature");
sampleRepo.write("Jenkinsfile", "// yet more");
sampleRepo.git("commit", "--all", "--message=newfeature-3");
sampleRepo.git("checkout", "release");
sampleRepo.write("Jenkinsfile", "// yet more");
sampleRepo.git("commit", "--all", "--message=release-3");
sampleRepo.notifyCommit(r);
}

}
@@ -34,15 +34,20 @@
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import jenkins.branch.BranchProperty;
import jenkins.branch.BranchPropertyDescriptor;
import jenkins.branch.BranchPropertyStrategy;
import jenkins.branch.BranchPropertyStrategyDescriptor;
import jenkins.branch.BranchSource;
import jenkins.branch.DefaultBranchPropertyStrategy;
import jenkins.branch.NamedExceptionsBranchPropertyStrategy;
import jenkins.branch.NoTriggerBranchProperty;
import jenkins.plugins.git.GitSCMSource;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.SCMSource;
@@ -127,19 +132,21 @@ static void showIndexing(@Nonnull WorkflowMultiBranchProject mp) throws Exceptio
System.out.println("---%<--- ");
}

@Issue("JENKINS-32670")
@Issue({"JENKINS-32396", "JENKINS-32670"})
@Test public void visibleBranchProperties() throws Exception {
WorkflowMultiBranchProject p = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
Set<Class<? extends BranchProperty>> clazzes = new HashSet<Class<? extends BranchProperty>>();
Set<Class<? extends BranchProperty>> propertyTypes = new HashSet<>();
for (BranchPropertyDescriptor d : DescriptorVisibilityFilter.apply(p, BranchPropertyDescriptor.all())) {
clazzes.add(d.clazz);
propertyTypes.add(d.clazz);
}
// RateLimitBranchProperty & BuildRetentionBranchProperty hidden by JobPropertyStep.HideSuperfluousBranchProperties.
// UntrustedBranchProperty hidden because it applies only to Project.
assertEquals(Collections.<Class<? extends BranchProperty>>emptySet(), clazzes);
/* TODO uncomment when branch-api 1.5+:
assertEquals(Collections.<BranchPropertyStrategyDescriptor>emptyList(), r.jenkins.getDescriptorByType(BranchSource.DescriptorImpl.class).propertyStrategyDescriptors(p, r.jenkins.getDescriptorByType(SingleSCMSource.DescriptorImpl.class)));
*/
assertEquals(Collections.singleton(NoTriggerBranchProperty.class), propertyTypes);
Set<Class<? extends BranchPropertyStrategy>> strategyTypes = new HashSet<>();
for (BranchPropertyStrategyDescriptor d : r.jenkins.getDescriptorByType(BranchSource.DescriptorImpl.class).propertyStrategyDescriptors(p, r.jenkins.getDescriptorByType(SingleSCMSource.DescriptorImpl.class))) {
strategyTypes.add(d.clazz);
}
assertEquals(new HashSet<>(Arrays.asList(DefaultBranchPropertyStrategy.class, NamedExceptionsBranchPropertyStrategy.class)), strategyTypes);
}

@SuppressWarnings("rawtypes")

0 comments on commit 5574409

Please sign in to comment.