package org.jenkinsci.plugins.p4.scm; import edu.umd.cs.findbugs.annotations.CheckForNull; import edu.umd.cs.findbugs.annotations.NonNull; import jenkins.scm.api.SCMHead; import jenkins.scm.api.SCMRevision; import jenkins.scm.api.trait.SCMBuilder; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.review.P4Review; import org.jenkinsci.plugins.p4.tasks.CheckoutStatus; public class P4ScmBuilder extends SCMBuilder<P4ScmBuilder, PerforceScm> { private final AbstractP4ScmSource source; private final P4Revision revision; public P4ScmBuilder(@NonNull AbstractP4ScmSource source, @NonNull SCMHead head, @CheckForNull SCMRevision revision) { super(PerforceScm.class, head, revision); this.source = source; if(revision instanceof P4Revision) { this.revision = (P4Revision) revision; } else { this.revision = null; } } @NonNull @Override public PerforceScm build() { if (head() instanceof P4ChangeRequestSCMHead) { P4ChangeRequestSCMHead perforceTag = (P4ChangeRequestSCMHead) head(); P4Path path = perforceTag.getPath(); PerforceScm scm = new PerforceScm(source, path, revision); P4Review review = new P4Review(head().getName(), CheckoutStatus.SHELVED); scm.setReview(review); return scm; } if (head() instanceof P4GraphRequestSCMHead) { P4GraphRequestSCMHead graphTag = (P4GraphRequestSCMHead) head(); P4Path path = graphTag.getPath(); PerforceScm scm = new PerforceScm(source, path, revision); return scm; } if (head() instanceof P4Head) { P4Head perforceHead = (P4Head) head(); P4Path path = perforceHead.getPath(); PerforceScm scm = new PerforceScm(source, path, revision); return scm; } throw new IllegalArgumentException("SCMHead not a Perforce instance!"); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 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'. |
||
#4 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#3 | 24500 | Paul Allen | Tidyup and refactor P4Ref classes. | ||
#2 | 24497 | Paul Allen |
Force use of revision for Head. Update P4Head->P4Path revision with P4Revision to avoid builds on unbounded 'latest'. |
||
#1 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |