package org.jenkinsci.plugins.p4; import hudson.Extension; import hudson.XmlFile; import hudson.model.Descriptor; import hudson.model.Saveable; import hudson.model.listeners.SaveableListener; import hudson.scm.SCM; import hudson.util.LogTaskListener; import jenkins.model.Jenkins; import org.jenkinsci.plugins.p4.PerforceScm.DescriptorImpl; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.publish.SubmitImpl; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @Extension public class ConfigurationListener extends SaveableListener { private static Logger logger = Logger.getLogger(ConfigurationListener.class.getName()); public void onChange(Saveable o, XmlFile xml) { Jenkins j = Jenkins.getInstance(); if (j == null) { return; } @SuppressWarnings("unchecked") Descriptor<SCM> scm = j.getDescriptor(PerforceScm.class); DescriptorImpl p4scm = (DescriptorImpl) scm; // Exit early if disabled if (!p4scm.isAutoSave()) { return; } try { String file = xml.getFile().getCanonicalPath(); logger.info(">>> onUpdated: " + file); // create Publish object String desc = "Configuration change"; boolean success = false; boolean delete = true; boolean reopen = false; String purge = ""; SubmitImpl publish = new SubmitImpl(desc, success, delete, reopen, purge); ClientHelper p4 = getClientHelper(p4scm); p4.versionFile(file, publish); p4.disconnect(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private ClientHelper getClientHelper(DescriptorImpl p4scm) throws Exception { LogTaskListener listener = new LogTaskListener(logger, Level.INFO); String credential = p4scm.getCredential(); String clientName = p4scm.getClientName(); String depotPath = p4scm.getDepotPath(); depotPath = depotPath.endsWith("/") ? depotPath : depotPath + "/"; Jenkins j = Jenkins.getInstance(); if (j == null) { return null; } String rootPath = j.getRootDir().getCanonicalPath(); StringBuffer view = new StringBuffer(); view.append(depotPath + "..."); view.append(" "); view.append("//" + clientName + "/..."); WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, "", "local", view.toString()); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("utf8", false, clientName, spec); workspace.setExpand(new HashMap<String, String>()); workspace.setRootPath(rootPath); ClientHelper p4 = new ClientHelper(Jenkins.getActiveInstance(), credential, listener, clientName, "utf8"); p4.setClient(workspace); return p4; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 21940 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/ConfigurationListener.java | |||||
#6 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#5 | 20954 | Paul Allen |
Add purge -S<n> option for the Submit stage of Publish. If a value is provided it will set the purge option on all files found as part of the reconcile (ADD/EDIT). It will not remove the purge option once set. JENKINS-36112 |
||
#4 | 19581 | Paul Allen | Minor fixes to satisfy FindBugs Analysis. | ||
#3 | 19454 | Paul Allen |
Hide P4_TICKET for secure systems. An option in the global configuration to hide the P4_TICKET variable (not set by default). JENKINS-24591 |
||
#2 | 17263 | Paul Allen |
Added enable/disable option for auto versioning. Global option to activate Perforce versioning of Jenkins Configurations. |
||
#1 | 16836 | Paul Allen |
Versioning for Jenkins configuration pages. Add credential, depot path location and client workspace name, everything else should be automatic. JENKINS-25145 |