package org.jenkinsci.plugins.p4.trigger; import hudson.Extension; import hudson.Util; import hudson.console.AnnotatedLargeText; import hudson.model.Action; import hudson.model.Item; import hudson.model.AbstractProject; import hudson.model.Job; import hudson.scm.PollingResult; import hudson.scm.SCM; import hudson.triggers.Trigger; import hudson.triggers.TriggerDescriptor; import hudson.util.StreamTaskListener; import java.io.File; import java.io.IOException; import java.io.PrintStream; import java.nio.charset.Charset; import java.util.Collection; import java.util.Collections; import java.util.logging.Logger; import jenkins.triggers.SCMTriggerItem; import org.apache.commons.jelly.XMLOutput; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.credentials.P4BaseCredentials; import org.kohsuke.stapler.DataBoundConstructor; public class P4Trigger extends Trigger<Job<?, ?>> { @DataBoundConstructor public P4Trigger() { } @Extension public static class DescriptorImpl extends TriggerDescriptor { @Override public boolean isApplicable(Item item) { return item instanceof Job; } @Override public String getDisplayName() { return "Perforce triggered build."; } } public void poke(Job<?, ?> job, String port) throws IOException { // exit early if job does not match trigger if (!matchServer(job, port)) { return; } LOGGER.info("P4: poking: " + job.getName()); StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream log = listener.getLogger(); SCMTriggerItem item = SCMTriggerItem.SCMTriggerItems .asSCMTriggerItem(job); PollingResult pollResult = item.poll(listener); if (pollResult.hasChanges()) { log.println("Changes found"); } else { log.println("No changes"); } } catch (Exception e) { String msg = "P4: Failed to record P4 trigger: "; e.printStackTrace(listener.error(msg)); LOGGER.severe(msg + e); } finally { listener.close(); } } public File getLogFile() { return new File(job.getRootDir(), "p4trigger.log"); } private boolean matchServer(Job<?, ?> job, String port) { if (job instanceof AbstractProject) { AbstractProject<?, ?> project = (AbstractProject<?, ?>) job; SCM scm = project.getScm(); if (scm instanceof PerforceScm) { PerforceScm p4scm = (PerforceScm) scm; String id = p4scm.getCredential(); P4BaseCredentials credential = ConnectionHelper .findCredential(id); if (port.equals(credential.getP4port())) { return true; } } } return false; } final static Logger LOGGER = Logger.getLogger(P4Trigger.class.getName()); /** * Perforce Trigger Log Action * * @author pallen * */ public final class P4TriggerAction implements Action { public Job<?, ?> getOwner() { return job; } public String getIconFileName() { return "clipboard.png"; } public String getDisplayName() { return "P4 Trigger Log"; } public String getUrlName() { return "P4TriggerLog"; } public String getLog() throws IOException { return Util.loadFile(getLogFile()); } /** * Writes the annotated log to the given output. */ public void writeLogTo(XMLOutput out) throws IOException { new AnnotatedLargeText<P4TriggerAction>(getLogFile(), Charset.defaultCharset(), true, this).writeHtmlTo(0, out.asWriter()); } } @Override public Collection<? extends Action> getProjectActions() { return Collections.singleton(new P4TriggerAction()); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#16 | 29411 | Paul Allen |
Merge pull request #171 from skumar7322/SecurityPatch Security Patch : Update Jenkins Version and Other Dependencies |
||
#15 | 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 |
||
#14 | 26593 | Paul Allen |
P4Trigger support for Folder based credentials. Avoid deprecated findCredential method and use the 'job' as the Item. JENKINS-62811 |
||
#13 | 26581 | Paul Allen |
Return "ssl:" on P4PORT for SSL connections Use 'contains' check on trigger checks for backwards compatability. JENKINS-62253 |
||
#12 | 25439 | Paul Allen |
Skip polling if Job is in WaitingItem Queue. JENKINS-56037 JENKINS-56286 |
||
#11 | 22840 | Paul Allen |
Merge pull request #49 from aosterkamp/master add support for "P4Trigger" declarative pipeline trigger |
||
#10 | 22245 | Paul Allen |
P4Trigger use locally defined job and not super class. JENKINS-44251 |
||
#9 | 21132 | Paul Allen | FindBugs: Null Pointer Checks | ||
#8 | 20226 | Paul Allen |
Support for Multiple SCMs Plugin. Optional dependency on multiple-scms and helper method for safely casting SCM object to PerforceSCM instance, especially in the scenario where the SCM object is a MultiSCM instance. JENKINS-32064 |
||
#7 | 20179 | Paul Allen | Javadoc fixes for java 8 builds. | ||
#6 | 19641 | Paul Allen |
Merge pull request #26 from Dohbedoh/hotfix/JENKINS-25249 [JENKINS-25249]: Fixed Null Pointer dereference |
||
#5 | 19630 | Paul Allen |
Merge pull request #24 from Dohbedoh/JENKINS-25249 Changes to make the P4 Trigger pipeline compatible. Added some tests of the P4 trigger for both Pipeline/Non Pipeline jobs. |
||
#4 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#3 | 19294 | Paul Allen |
Schedule build on trigger for subscribed Jobs. JENKINS-33858 |
||
#2 | 15656 | Paul Allen |
Updated credentials to extend BaseStandardCredentials. Allows users to set the ID at creation. JENKINS-29702 |
||
#1 | 15403 | Paul Allen |
Perforce triggered polling BETA. Perforce triggers on a change-submit and sends a POST to the endpoint http://${JENKINS}/p4/change with the data: {"change":"12345","p4port":"localhost:1666"} Note: ‘change’ is not used (yet), but ‘p4port’ MUST match the credential in the Jenkins Job. JENKINS-25249 |