package org.jenkinsci.plugins.p4.scm; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.model.TaskListener; import jenkins.scm.api.SCMHead; import jenkins.scm.api.SCMHeadEvent; import jenkins.scm.api.SCMHeadObserver; import jenkins.scm.api.SCMRevision; import jenkins.scm.api.SCMSource; import jenkins.scm.api.SCMSourceCriteria; import jenkins.scm.api.SCMSourceOwner; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.browsers.P4Browser; import org.jenkinsci.plugins.p4.changes.P4ChangeRef; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.review.P4Review; 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.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory; import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; import org.kohsuke.stapler.DataBoundSetter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Logger; public abstract class AbstractP4ScmSource extends SCMSource { private static Logger logger = Logger.getLogger(AbstractP4ScmSource.class.getName()); public static final String scmSourceClient = "jenkins-master"; protected final String credential; private String includes; private String charset; private String format; private Populate populate; public AbstractP4ScmSource(String id, String credential) { super(id); this.credential = credential; } @DataBoundSetter public void setFormat(String format) { this.format = format; } @DataBoundSetter public void setPopulate(Populate populate) { this.populate = populate; } @DataBoundSetter public void setIncludes(String includes) { this.includes = includes; } @DataBoundSetter public void setCharset(String charset) { this.charset = charset; } public String getCredential() { return credential; } public String getIncludes() { return includes; } public String getCharset() { return charset; } public String getFormat() { return format; } public Populate getPopulate() { return populate; } public abstract P4Browser getBrowser(); public abstract List<P4Head> getHeads(@NonNull TaskListener listener) throws Exception; public abstract List<P4Head> getTags(@NonNull TaskListener listener) throws Exception; public Workspace getWorkspace(List<P4Path> paths) { String client = getFormat(); String scriptPath = getScriptPathOrDefault("Jenkinsfile"); StringBuffer sb = new StringBuffer(); for (P4Path path : paths) { String view = String.format("%s/%s //%s/%s", path.getPath(), scriptPath, client, scriptPath); sb.append(view).append("\n"); } WorkspaceSpec spec = new WorkspaceSpec(sb.toString(), null); return new ManualWorkspaceImpl(getCharset(), false, client, spec); } protected String getScriptPathOrDefault(String defaultScriptPath) { SCMSourceOwner owner = getOwner(); if(owner instanceof WorkflowMultiBranchProject){ WorkflowMultiBranchProject branchProject = (WorkflowMultiBranchProject) owner; WorkflowBranchProjectFactory branchProjectFactory = (WorkflowBranchProjectFactory) branchProject.getProjectFactory(); return branchProjectFactory.getScriptPath(); } return defaultScriptPath; } @Override public PerforceScm build(SCMHead head, SCMRevision revision) { if (head instanceof P4ChangeRequestSCMHead) { P4ChangeRequestSCMHead perforceTag = (P4ChangeRequestSCMHead) head; List<P4Path> paths = perforceTag.getPaths(); Workspace workspace = getWorkspace(paths); PerforceScm scm = new PerforceScm(getCredential(), workspace, null, getPopulate(), getBrowser()); P4Review review = new P4Review(head.getName(), CheckoutStatus.SHELVED); scm.setReview(review); return scm; } if (head instanceof P4GraphRequestSCMHead) { P4GraphRequestSCMHead graphTag = (P4GraphRequestSCMHead) head; List<P4Path> paths = graphTag.getPaths(); Workspace workspace = getWorkspace(paths); PerforceScm scm = new PerforceScm(getCredential(), workspace, null, getPopulate(), getBrowser()); return scm; } if (head instanceof P4Head) { P4Head perforceHead = (P4Head) head; List<P4Path> paths = perforceHead.getPaths(); Workspace workspace = getWorkspace(paths); PerforceScm scm = new PerforceScm(getCredential(), workspace, null, getPopulate(), getBrowser()); return scm; } throw new IllegalArgumentException("SCMHead not a Perforce instance!"); } @Override protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer, @CheckForNull SCMHeadEvent<?> event, @NonNull TaskListener listener) throws IOException, InterruptedException { try { List<P4Head> heads = getHeads(listener); List<P4Head> tags = getTags(listener); heads.addAll(tags); for (P4Head head : heads) { // null criteria means that all branches match. if (criteria == null) { // get revision and add observe SCMRevision revision = getRevision(head, listener); observer.observe(head, revision); } else { ClientHelper p4 = new ClientHelper(getOwner(), credential, listener, scmSourceClient, charset); SCMSourceCriteria.Probe probe = new P4Probe(p4, head); if (criteria.isHead(probe, listener)) { // get revision and add observe SCMRevision revision = getRevision(head, listener); observer.observe(head, revision); } } // check for user abort checkInterrupt(); } } catch (Exception e) { throw new IOException(e.getMessage()); } } protected List<String> getIncludePaths() { return toLines(includes); } protected List<String> toLines(String value) { if(value == null) { return new ArrayList<>(); } String[] array = value.split("[\\r\\n]+"); return Arrays.asList(array); } public P4Revision getRevision(P4Head head, TaskListener listener) throws Exception { try (ClientHelper p4 = new ClientHelper(getOwner(), credential, listener, scmSourceClient, charset)) { // TODO look for graph revisions too long change = -1; for (P4Path path : head.getPaths()) { String rev = path.getRevision(); rev = (rev != null && !rev.isEmpty()) ? "/...@" + rev : "/..."; long c = p4.getHead(path.getPath() + rev); change = (c > change) ? c : change; } P4Revision revision = new P4Revision(head, new P4ChangeRef(change)); return revision; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#39 | 28735 | Paul Allen |
Merge pull request #142 from skumar7322/branchIndexing JENKINS-64946 : Branch indexing occurring for every multibranch job |
||
#38 | 28015 | Paul Allen |
MultiBranch exclude filter. A regular expression exclude filter for Swarm branches, Stream names and Branch paths. JENKINS-58346 JENKINS-63625 |
||
#37 | 27492 | Paul Allen |
Add new Filter to build with the latest change found during polling. JENKINS-63879 |
||
#36 | 27175 | Paul Allen |
Prevent dormant multi branch project continiously building. JENKINS-63494 and JENKINS-64193 When scanning a multi branch project if the history of changes is outside of the `Head change query limit` then no changes are found. The old behaviour used the latest change and triggered a build; continuously triggering dormant projects with each new submit. The new behaviour uses the last build change if no changes are found (preventing a triggered build) or if there was no previous builds (in the case of new projects) then the latest changes is used to triggering a build. |
||
#35 | 26603 | Paul Allen |
Merge pull request #119 from joel-f-brown/master Add virtual stream detection for MultiBranch pipeline. JENKINS-62699 |
||
#34 | 26602 | Paul Allen |
Reuse temp client connections for the multi-branch scan. TempClientHelper is set in retrieve and updated for different heads. |
||
#33 | 26601 | Paul Allen | Code cleanup for getHead and getLowestHead. | ||
#32 | 26585 | Paul Allen |
Use a TempClientHelper to map the P4Path and then check for changes. JENKINS-62259 |
||
#31 | 26568 | Paul Allen | Prevent double @@ if limit is empty. | ||
#30 | 26423 | Paul Allen |
Add range limit for MultiBranch head revision queries. JENKINS-61745 |
||
#29 | 26207 | Paul Allen | Making previous changes in AbstractP4ScmSource.java more efficient. | ||
#28 | 26206 | Paul Allen | Making Polling ignore "default jenkinsfile" when "Pipeline: Multibranch with defaults" plugin is installed and instead use the word "jenkinsfile" as the jenkinsfile location. | ||
#27 | 25843 | Paul Allen | MultiBranch support for Swarm path Exclusions in the project configuration. | ||
#26 | 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 |
||
#25 | 25015 | Paul Allen | Enable/Disable MultiBranch Scan per change using Polling Filter. | ||
#24 | 25014 | Paul Allen |
Scan per change support for MultiBranch with remote Jenkinsfiles. Only the 'Polling per Change' Filter is supported; need to disable or support the other filter types. JENKINS-53936 |
||
#23 | 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 |
||
#22 | 24767 | Paul Allen |
Global Library support for multiple instances. Enforce a depot syntax path ending of "/..." Remove 'beta' from Global Library configuration. Generate a unique workspace to sync multiple Libraries. JENKINS-53922 |
||
#21 | 24662 | Paul Allen |
Undo *SCMSource rename to original *ScmSource. Reslove configuration loading issue due to 1.9.0 bad release. |
||
#20 | 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'. |
||
#19 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#18 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#17 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#16 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#15 | 23373 | Paul Allen |
Lightweight checkout support. Implementation for scm-api classes SCMFile and SCMFileSystem, allowing Jenkins to navigate Perforce within the scope of a workspace view. Lightweight checkout uses a tempoary Perforce workspace to naviagete and fetch the files. The client name and client view mapping will be modified from a template name e.g. jenkins-${NODE_NAME}-${JOB_NAME} to the tempoary name jenkinsTemp-UUID. Alternativly if a user as used ${P4_CLIENT} in the client mapping this will remain unchanged and will be get expanded during the job run. JENKINS-45999 JENKINS-46269 |
||
#14 | 23327 | Paul Allen | Use client less connection when scanning MultiBranch. | ||
#13 | 23324 | Paul Allen | Use short lived temporary client when scanning MultiBranch. | ||
#12 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#11 | 23261 | Paul Allen | Backwards compatibility for new Mappings field in MultiBranch. | ||
#10 | 23217 | Paul Allen |
Add the ability to provide a view spec to Helix Branches SCM Pr/61. Review Pr/64 |
||
#9 | 23028 | Paul Allen |
MultiBranch docs and tidy up. Move getScriptPathOrDefault and getWorkspace from Helix Branches to AbstractP4ScmSource. |
||
#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 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#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 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#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 |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/AbstractP4SCMSource.java | |||||
#4 | 24597 | Paul Allen | Fix P4Path bug on MultiBranch to include branch. | ||
#3 | 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. |
||
#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 | |
#19 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#18 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#17 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#16 | 24454 | Paul Allen |
Exclude and Include mapping support. Refactored P4Path usage and added P4SwarmPath. JENKINS-49804 |
||
#15 | 23373 | Paul Allen |
Lightweight checkout support. Implementation for scm-api classes SCMFile and SCMFileSystem, allowing Jenkins to navigate Perforce within the scope of a workspace view. Lightweight checkout uses a tempoary Perforce workspace to naviagete and fetch the files. The client name and client view mapping will be modified from a template name e.g. jenkins-${NODE_NAME}-${JOB_NAME} to the tempoary name jenkinsTemp-UUID. Alternativly if a user as used ${P4_CLIENT} in the client mapping this will remain unchanged and will be get expanded during the job run. JENKINS-45999 JENKINS-46269 |
||
#14 | 23327 | Paul Allen | Use client less connection when scanning MultiBranch. | ||
#13 | 23324 | Paul Allen | Use short lived temporary client when scanning MultiBranch. | ||
#12 | 23320 | Paul Allen | Remove deprecated ID for SCMSource constructor. | ||
#11 | 23261 | Paul Allen | Backwards compatibility for new Mappings field in MultiBranch. | ||
#10 | 23217 | Paul Allen |
Add the ability to provide a view spec to Helix Branches SCM Pr/61. Review Pr/64 |
||
#9 | 23028 | Paul Allen |
MultiBranch docs and tidy up. Move getScriptPathOrDefault and getWorkspace from Helix Branches to AbstractP4ScmSource. |
||
#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 | 22678 | Paul Allen |
MultiBranch support for Helix4Git (GitHub PR model). Update MultiBranch product names to Helix. |
||
#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 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#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 |