package org.jenkinsci.plugins.p4.scm; import jenkins.branch.BranchSource; import jenkins.scm.api.SCMSource; import org.jenkinsci.plugins.p4.DefaultEnvironment; import org.jenkinsci.plugins.p4.SampleServerRule; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.Assert.assertThat; public class PerforceScmSourceTest extends DefaultEnvironment { private static final String P4ROOT = "tmp-ScmSourceTest-p4root"; private static P4PasswordImpl auth; @ClassRule public static JenkinsRule jenkins = new JenkinsRule(); @Rule public SampleServerRule p4d = new SampleServerRule(P4ROOT, VERSION); @Before public void buildCredentials() throws Exception { auth = createCredentials("jenkins", "jenkins", p4d); } @Test public void testMultiBranchWithStreams() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new StreamsScmSource("streams", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-streams"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); WorkflowJob job = multi.getItem("Ace-main"); assertThat("We now have a branch", job, notNullValue()); WorkflowRun build = job.getLastBuild(); assertThat("The branch was built", build, notNullValue()); assertThat("The branch was built", build.getNumber(), is(1)); } @Test public void testMultiBranchWithClassic() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new BranchesScmSource("classic", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-classic"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); WorkflowJob job = multi.getItem("Ace-main"); assertThat("We now have a branch", job, notNullValue()); WorkflowRun build = job.getLastBuild(); assertThat("The branch was built", build, notNullValue()); assertThat("The branch was built", build.getNumber(), is(1)); } @Test public void testNoMultiStreams() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//depot/..."; SCMSource source = new StreamsScmSource("no-streams", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "no-streams"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We have no branches", multi.getItems(), containsInAnyOrder()); } @Test public void testSimplePathStreams() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream"; SCMSource source = new StreamsScmSource("path-streams", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "path-streams"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } @Test public void testSimplePathClassic() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream"; SCMSource source = new BranchesScmSource("path-classic", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "path-classic"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } @Test public void testStarPathClassic() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/*"; SCMSource source = new BranchesScmSource("star-classic", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "star-classic"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } @Test public void testRootPathClassic() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//..."; SCMSource source = new BranchesScmSource("root-classic", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "root-classic"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } @Test public void testRootPathStreams() throws Exception { String credential = auth.getId(); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//..."; SCMSource source = new StreamsScmSource("root-streams", credential, includes, null, format, null); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "root-streams"); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#14 | 24504 | Paul Allen |
Tree walter for BranchSCMSource Events. On a change-submit event use the change number and grab a submitted file. Walk up the path looking for a Jenkinsfile, then derive 'Project' path, 'Branch' name and 'Path' for the SCMHead/Revision. This assumes that the Jenkinsfile is in the route of your projects. Alternatively use the Swarm Event and pass your own 'Project', 'Branch' and 'Path'. |
||
#13 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#12 | 24500 | Paul Allen | Tidyup and refactor P4Ref classes. | ||
#11 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#10 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#9 | 24455 | Paul Allen |
Allow query of single streams by appending a `*` to a streams path. https://github.com/p4paul/p4-jenkins/issues/36 |
||
#8 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#7 | 24403 | Paul Allen |
Support spaces in depot path for MultiBranch and DepotSource JENKINS-52604 |
||
#6 | 23819 | Paul Allen | Cleanup test cases to use Credential ID. | ||
#5 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#4 | 22396 | Paul Allen |
MultiBranch support for Perforce Swarm Reviews. A work in progress - adds Swarm API support to find branches and reviews from a Swarm project. #review-22354 |
||
#3 | 21936 | Paul Allen |
Refactor tests for 17.1 release. Removed pseudo web server on FreeStyleTest |
||
#2 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#1 | 21758 | Paul Allen |
Merge pull request #38 from jenkinsci/dev scm-api 2.0.2 updates |