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.changes.P4Ref; import org.jenkinsci.plugins.p4.changes.P4RefBuilder; import org.jenkinsci.plugins.p4.review.P4Review; import org.jenkinsci.plugins.p4.tasks.CheckoutStatus; import java.util.logging.Logger; public class P4SCMBuilder extends SCMBuilder<P4SCMBuilder, PerforceScm> { private static Logger logger = Logger.getLogger(P4SCMBuilder.class.getName()); private final AbstractP4SCMSource source; private final P4Path path; private final P4Ref revision; public P4SCMBuilder(@NonNull AbstractP4SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision revision) { super(PerforceScm.class, head, revision); this.source = source; if (head instanceof P4SCMHead) { P4SCMHead p4head = (P4SCMHead) head; if (p4head.getPath() != null) { this.path = p4head.getPath(); } else { this.path = null; } } else { this.path = null; } // TODO: // Not sure about this, Jenkins seems to ignore revision and send a null. // So use P4Path's revision from head... if (path != null && path.getRevision() != null) { String rev = path.getRevision(); this.revision = P4RefBuilder.get(rev); } else { this.revision = null; } logger.info("SCM: P4SCMBuilder: " + head + "(" + revision + ")"); } @NonNull @Override public PerforceScm build() { if (head() instanceof P4ChangeRequestSCMHead) { PerforceScm scm = new PerforceScm(source, path, revision); P4Review review = new P4Review(head().getName(), CheckoutStatus.SHELVED); scm.setReview(review); return scm; } if (head() instanceof P4GraphRequestSCMHead) { PerforceScm scm = new PerforceScm(source, path, revision); return scm; } if (head() instanceof P4SCMHead) { 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) |