package org.jenkinsci.plugins.p4.scm; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.Extension; import hudson.model.TaskListener; import jenkins.scm.api.SCMHead; import jenkins.scm.api.SCMHeadCategory; import jenkins.scm.api.SCMRevision; import jenkins.scm.impl.ChangeRequestSCMHeadCategory; import jenkins.scm.impl.UncategorizedSCMHeadCategory; import jenkins.util.NonLocalizable; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.browsers.P4Browser; import org.jenkinsci.plugins.p4.browsers.SwarmBrowser; import org.jenkinsci.plugins.p4.changes.P4ChangeRef; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.client.ViewMapHelper; import org.jenkinsci.plugins.p4.review.P4Review; import org.jenkinsci.plugins.p4.swarmAPI.SwarmHelper; import org.jenkinsci.plugins.p4.swarmAPI.SwarmProjectAPI; import org.jenkinsci.plugins.p4.swarmAPI.SwarmReviewAPI; import org.jenkinsci.plugins.p4.swarmAPI.SwarmReviewsAPI; import org.jenkinsci.plugins.p4.tasks.CheckoutStatus; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; public class SwarmScmSource extends AbstractP4ScmSource { private String project; transient private SwarmHelper swarm; @DataBoundConstructor public SwarmScmSource(String credential, String charset, String format) throws Exception { super(credential); setCharset(charset); setFormat(format); } @DataBoundSetter public void setProject(String project) { this.project = project; } public String getProject() { return project; } public SwarmHelper getSwarm() throws Exception { if (swarm == null) { try (ConnectionHelper p4 = new ConnectionHelper(getOwner(), credential, null)) { this.swarm = new SwarmHelper(p4, "4"); } } return swarm; } @Override public P4Browser getBrowser() { try { return new SwarmBrowser(getSwarm().getBaseUrl()); } catch (Exception e) { return null; } } @Override public List<P4Head> getTags(@NonNull TaskListener listener) throws Exception { List<P4Head> list = new ArrayList<>(); List<SwarmReviewsAPI.Reviews> reviews = getSwarm().getActiveReviews(project); for (SwarmReviewsAPI.Reviews review : reviews) { String reviewID = String.valueOf(review.getId()); List<String> branches = getBranchesInReview(reviewID, project); for (String branch : branches) { // Get first Swarm path; it MUST include the Jenkinsfile P4SwarmPath swarmPath = getPathsInBranch(branch, project); String trgName = branch + "-" + reviewID; P4Head target = new P4Head(trgName, swarmPath); P4ChangeRequestSCMHead tag = new P4ChangeRequestSCMHead(trgName, reviewID, swarmPath, target); list.add(tag); } } return list; } @Override public List<P4Head> getHeads(@NonNull TaskListener listener) throws Exception { List<P4Head> list = new ArrayList<>(); List<SwarmProjectAPI.Branch> branches = getSwarm().getBranchesInProject(project); for (SwarmProjectAPI.Branch branch : branches) { // Get first Swarm path; it MUST include the Jenkinsfile P4SwarmPath swarmPath = branch.getPath(); P4Head head = new P4Head(branch.getId(), swarmPath); list.add(head); } return list; } @Override public P4Revision getRevision(P4Head head, TaskListener listener) throws Exception { if (head instanceof P4ChangeRequestSCMHead) { P4ChangeRequestSCMHead changeRequest = (P4ChangeRequestSCMHead) head; String review = changeRequest.getReview(); long change = getLastChangeInReview(review); P4Revision revision = new P4Revision(head, new P4ChangeRef(change)); return revision; } return super.getRevision(head, listener); } @Override public PerforceScm build(@NonNull SCMHead head, SCMRevision revision) { PerforceScm scm = super.build(head, revision); if (head instanceof P4ChangeRequestSCMHead) { P4Review review = new P4Review(head.getName(), CheckoutStatus.SHELVED); scm.setReview(review); } return scm; } @Override public Workspace getWorkspace(P4Path path) { if (path == null || !(path instanceof P4SwarmPath)) { throw new IllegalArgumentException("missing Swarm path"); } P4SwarmPath swarmPath = (P4SwarmPath) path; String client = getFormat(); String jenkinsPath = path.getPath() + "/" + getScriptPathOrDefault(); String jenkinsView = ViewMapHelper.getClientView(jenkinsPath, client); String mappingsView = ViewMapHelper.getClientView(swarmPath.getMappings(), client); String view = jenkinsView + "\n" + mappingsView; WorkspaceSpec spec = new WorkspaceSpec(view, null); return new ManualWorkspaceImpl(getCharset(), false, client, spec); } protected boolean isCategoryEnabled(@NonNull SCMHeadCategory category) { return true; } private List<String> getBranchesInReview(String review, String project) throws Exception { SwarmReviewAPI api = getSwarm().getSwarmReview(review); HashMap<String, List<String>> projects = api.getReview().getProjects(); List<String> branches = projects.get(project); return branches; } private long getLastChangeInReview(String review) throws Exception { SwarmReviewAPI api = getSwarm().getSwarmReview(review); List<Long> changes = api.getReview().getChanges(); long lastChange = 0; for (Long change : changes) { if (change > lastChange) { lastChange = change; } } return lastChange; } private P4SwarmPath getPathsInBranch(String id, String project) throws Exception { List<SwarmProjectAPI.Branch> branches = getSwarm().getBranchesInProject(project); for (SwarmProjectAPI.Branch branch : branches) { if (id.equals(branch.getId())) { P4SwarmPath swarmPath = branch.getPath(); return swarmPath; } } return null; } @Extension @Symbol("multiSwarm") public static final class DescriptorImpl extends P4ScmSourceDescriptor { @Override public String getDisplayName() { return "Helix Swarm"; } @NonNull @Override protected SCMHeadCategory[] createCategories() { return new SCMHeadCategory[]{ new UncategorizedSCMHeadCategory(new NonLocalizable("Branches")), new ChangeRequestSCMHeadCategory(new NonLocalizable("Reviews")) }; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#32 | 30143 | Sandeep Kumar |
Merge pull request #[197] from [skumar7322/SwarmAPI] Change Swarm API version to v11 |
||
#31 | 29673 | Sandeep Kumar |
Merge pull request #188 from jenkinsci/CodeRefactoring Code Cleanup |
||
#30 | 28015 | Paul Allen |
MultiBranch exclude filter. A regular expression exclude filter for Swarm branches, Stream names and Branch paths. JENKINS-58346 JENKINS-63625 |
||
#29 | 27770 | Paul Allen | Update Swarm API to v9 | ||
#28 | 26955 | Paul Allen |
Merge pull request #125 from dvilaverde/master Add ContributorMetadataAction to SwarmScmSource to enable CHANGE_AUTHOR env variable in build |
||
#27 | 26938 | Paul Allen |
Merge pull request #122 from dvilaverde/master Have P4ChangeRequestSCMHead implement interface ChangeRequestSCMHead2 |
||
#26 | 26930 | Paul Allen |
Merge pull request #124 from dvilaverde/case-sensitive SwarmSCMSource#getHeads uses swarm id instead of name for P4SCMHead |
||
#25 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#24 | 26602 | Paul Allen |
Reuse temp client connections for the multi-branch scan. TempClientHelper is set in retrieve and updated for different heads. |
||
#23 | 25844 | Paul Allen | Change Swarm Reviews so that they are only identified by review number in the multi branch (for better rendering in BlueOcean). | ||
#22 | 25610 | Paul Allen |
Merge pull request #98 from stuartrowe/JENKINS-57358 [JENKINS-57358] Add null check before using P4Path object returned by method SwarmScmSource#getPathsInBranch |
||
#21 | 25564 | Paul Allen |
Merge branch 'local_map' MultiBranch support for 'HelixBranches' local and remote Mappings. Allows MultiBranches to map Depot paths external to the MultiBranch projects root. For example, a MultiBranch project with the following Jenkinsfiles: ProjA >> main //depot/projA/main/Jenkinsfile //depot/projA/main/src/... ProjA>> dev //depot/projA/dev/Jenkinsfile //depot/projA/dev/src/... An 'Includes' path for Branch Sources set to: //depot/projA/... Jenkins will now create two branches 'main' and 'dev'. The default Mapping is '...' so the 'src/...' and any other files under the branch root will appear in the project's workspace. To import an extenal location we can add another line to the mapping: ... //depot/external/stuff/... Now both branches 'main' and 'dev' will have a folder 'depot/external/stuff' with the mapped files. We can also use the `BRANCH_NAME` environment variable in the remote path uses the branch name. ... //depot/external/${BRANCH_NAME}/... and in 'main' you will now see the remote files in ' depot/external/main' along with the local project files mapped with '...' |
||
#20 | 25006 | Paul Allen |
Support for remote Jenkinsfiles in a MultiBranch project. Jenkinsfile are idenitified by the Include branches path (e.g. //depot/Remote/...), but you must add a Mapping in the BranchSource->Advanced->View Mappings to locate the projects source and use a special ${BRANCH_NAME} in the path. e.g. //depot/ProjectA/${BRANCH_NAME}/... JENKINS-53936 |
||
#19 | 24829 | Paul Allen |
Support Jenkinsfiles in sub directories. Preserve Jenkinsfile path in Client View. JENKINS-54382 |
||
#18 | 24670 | Paul Allen |
Swarm review support for MultiBranch scanning. Changed TempClient view map to add Jenkinsfile at the bottom. |
||
#17 | 24662 | Paul Allen |
Undo *SCMSource rename to original *ScmSource. Reslove configuration loading issue due to 1.9.0 bad release. |
||
#16 | 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'. |
||
#15 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#14 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#13 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#12 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#11 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#10 | 22937 | Paul Allen | Use Unirest for all Swarm API calls. | ||
#9 | 22881 | Paul Allen | Cache the BasicAuth token to avoid multiple login calls. | ||
#8 | 22875 | Paul Allen | Refactor P4Path and Swarm API | ||
#7 | 22866 | Paul Allen |
Merge pull request #55 from jenkinsci/hth Global Pipeline Library support. JENKINS-46121 JENKINS-46550 |
||
#6 | 22863 | Paul Allen | Store change in P4Revision as P4Ref. | ||
#5 | 22841 | Paul Allen |
Switch to `P4.Swarm.URL` property for Swarm url. JENKINS-45464 |
||
#4 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#3 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#2 | 22398 | Paul Allen | Pass Perforce ticket using BasicAuth to Swarm API. | ||
#1 | 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 |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/SwarmSCMSource.java | |||||
#5 | 24597 | Paul Allen | Fix P4Path bug on MultiBranch to include branch. | ||
#4 | 24571 | Paul Allen |
Support for Swarm pre-commit review events. Swarm pre-commit review event creates a new 'Reviews' Tag in the MultiBranch and builds with specified change and shelf. |
||
#3 | 24536 | Paul Allen |
Improved Swarm SCMRevision builder. Started to add Swarm Review Event support and exteded test case. JENKINS-52066 |
||
#2 | 24529 | Paul Allen |
Swarm Commit Event support, refactoring and test. JENKINS-52605 (Fix doc in 'Includes' help bubble for MultiBranch) JENKINS-52066 (Improve Swarm Commit and Branch Event support) |
||
#1 | 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'. |
||
# | Change | User | Description | Committed | |
#15 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#14 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#13 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#12 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#11 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#10 | 22937 | Paul Allen | Use Unirest for all Swarm API calls. | ||
#9 | 22881 | Paul Allen | Cache the BasicAuth token to avoid multiple login calls. | ||
#8 | 22875 | Paul Allen | Refactor P4Path and Swarm API | ||
#7 | 22866 | Paul Allen |
Merge pull request #55 from jenkinsci/hth Global Pipeline Library support. JENKINS-46121 JENKINS-46550 |
||
#6 | 22863 | Paul Allen | Store change in P4Revision as P4Ref. | ||
#5 | 22841 | Paul Allen |
Switch to `P4.Swarm.URL` property for Swarm url. JENKINS-45464 |
||
#4 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#3 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#2 | 22398 | Paul Allen | Pass Perforce ticket using BasicAuth to Swarm API. | ||
#1 | 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 |