package org.jenkinsci.plugins.p4.scm.events; import edu.umd.cs.findbugs.annotations.NonNull; import hudson.scm.SCM; import jenkins.scm.api.SCMHead; import jenkins.scm.api.SCMHeadEvent; import jenkins.scm.api.SCMNavigator; import jenkins.scm.api.SCMRevision; import jenkins.scm.api.SCMSource; import net.sf.json.JSONObject; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.credentials.P4BaseCredentials; import org.jenkinsci.plugins.p4.review.ReviewProp; import org.jenkinsci.plugins.p4.scm.AbstractP4ScmSource; import org.jenkinsci.plugins.p4.scm.P4SCMRevision; import java.util.Collections; import java.util.Map; public class P4BranchSCMHeadEvent extends SCMHeadEvent<JSONObject> { public P4BranchSCMHeadEvent(@NonNull Type type, JSONObject payload, String origin) { super(type, payload, origin); } @NonNull @Override public String getSourceName() { String p4port = getField(getPayload(), ReviewProp.P4_PORT); String change = getField(getPayload(), ReviewProp.P4_CHANGE); return p4port + "/" + change; } @NonNull @Override public Map<SCMHead, SCMRevision> heads(@NonNull SCMSource scmSource) { // Verify SCMSource if (!(scmSource instanceof AbstractP4ScmSource)) { // Not a Perforce Source return Collections.emptyMap(); } AbstractP4ScmSource source = (AbstractP4ScmSource) scmSource; // Check Perforce server P4PORT String p4port = getField(getPayload(), ReviewProp.P4_PORT); String id = source.getCredential(); P4BaseCredentials credential = ConnectionHelper.findCredential(id, scmSource.getOwner()); if (p4port == null || !p4port.equals(credential.getP4port())) { return Collections.emptyMap(); } P4SCMRevision revision = source.getRevision(getPayload()); if(revision == null) { return Collections.emptyMap(); } return Collections.singletonMap(revision.getHead(), revision); } @Override public boolean isMatch(@NonNull SCM scm) { return true; } @Override public boolean isMatch(@NonNull SCMNavigator scmNavigator) { return false; } private static String getField(JSONObject payload, ReviewProp prop) { return payload.getString(prop.getProp()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 26617 | Paul Allen |
Prevent `ssl:` string from appearing in the P4PORT Jelly field. Jelly uses getP4port() method for binding the fields; adding the ssl prefix was causing issues. JENKINS-63246 |
||
#4 | 26581 | Paul Allen |
Return "ssl:" on P4PORT for SSL connections Use 'contains' check on trigger checks for backwards compatability. JENKINS-62253 |
||
#3 | 24662 | Paul Allen |
Undo *SCMSource rename to original *ScmSource. Reslove configuration loading issue due to 1.9.0 bad release. |
||
#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'. |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/scm/events/P4BranchScmHeadEvent.java | |||||
#3 | 24501 | Paul Allen | Refactor to use P4SCMXxx naming convention. | ||
#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) |