package org.jenkinsci.plugins.p4.scm; import com.cloudbees.hudson.plugins.folder.AbstractFolder; import com.cloudbees.hudson.plugins.folder.properties.FolderCredentialsProvider; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.CredentialsStore; import com.cloudbees.plugins.credentials.domains.Domain; import hudson.model.Result; 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.P4BaseCredentials; 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.assertEquals; import static org.junit.Assert.assertThat; public class PerforceScmSourceTest extends DefaultEnvironment { private static final String P4ROOT = "tmp-ScmSourceTest-p4root"; @ClassRule public static JenkinsRule jenkins = new JenkinsRule(); @Rule public SampleServerRule p4d = new SampleServerRule(P4ROOT, R15_1); @Before public void buildCredentials() throws Exception { createCredentials("jenkins", "jenkins", p4d.getRshPort(), CREDENTIAL); } @Test public void testMultiBranchWithStreams() throws Exception { String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new StreamsScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new BranchesScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//depot/..."; SCMSource source = new StreamsScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream"; SCMSource source = new StreamsScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream"; SCMSource source = new BranchesScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/*"; SCMSource source = new BranchesScmSource(CREDENTIAL, includes, null, format); 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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//..."; SCMSource source = new BranchesScmSource(CREDENTIAL, includes, null, format); 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 testSpacePathClassic() throws Exception { submitFile(jenkins, "//depot/space path/A/Jenkinsfile", "node() {}"); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//depot/space path/..."; SCMSource source = new BranchesScmSource(CREDENTIAL, includes, null, format); WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "space-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 format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//..."; SCMSource source = new StreamsScmSource(CREDENTIAL, includes, null, format); 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())); } @Test public void testMultiBranchClassicWithCredentialsInFolder() throws Exception { WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-classic-creds-in-folder"); CredentialsStore folderStore = getFolderStore(multi); P4BaseCredentials inFolderCredentials = new P4PasswordImpl( CredentialsScope.GLOBAL, "idInFolder", "desc:passwd", p4d.getRshPort(), null, "jenkins", "0", "0", null, "jenkins"); folderStore.addCredentials(Domain.global(), inFolderCredentials); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new BranchesScmSource(inFolderCredentials.getId(), includes, null, format); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertEquals("Branch Indexing succeeded", Result.SUCCESS, multi.getComputation().getResult()); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } @Test public void testMultiBranchStreamWithCredentialsInFolder() throws Exception { WorkflowMultiBranchProject multi = jenkins.jenkins.createProject(WorkflowMultiBranchProject.class, "multi-streams-creds-in-folder"); CredentialsStore folderStore = getFolderStore(multi); P4BaseCredentials inFolderCredentials = new P4PasswordImpl( CredentialsScope.GLOBAL, "idInFolder", "desc:passwd", p4d.getRshPort(), null, "jenkins", "0", "0", null, "jenkins"); folderStore.addCredentials(Domain.global(), inFolderCredentials); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; String includes = "//stream/..."; SCMSource source = new StreamsScmSource(inFolderCredentials.getId(), includes, null, format); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); jenkins.waitUntilNoActivity(); assertEquals("Branch Indexing succeeded", Result.SUCCESS, multi.getComputation().getResult()); assertThat("We now have branches", multi.getItems(), not(containsInAnyOrder())); } private CredentialsStore getFolderStore(AbstractFolder f) { Iterable<CredentialsStore> stores = CredentialsProvider.lookupStores(f); CredentialsStore folderStore = null; for (CredentialsStore s : stores) { if (s.getProvider() instanceof FolderCredentialsProvider && s.getContext() == f) { folderStore = s; break; } } return folderStore; } }
# | 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 |