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.client.ViewMapHelper; 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 final Logger logger = Logger.getLogger(ConfigurationListener.class.getName()); public void onChange(Saveable o, XmlFile xml) { Jenkins j = Jenkins.getInstance(); @SuppressWarnings("unchecked") Descriptor<SCM> scm = j.getDescriptor(PerforceScm.class); DescriptorImpl p4scm = (DescriptorImpl) scm; // Exit early if disabled if (p4scm == null || !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 modtime = false; boolean reopen = false; String purge = ""; SubmitImpl publish = new SubmitImpl(desc, success, delete, modtime, reopen, purge); try (ClientHelper p4 = getClientHelper(p4scm)) { int ChangelistID = -1; if (!p4scm.isAutoSubmitOnChange()) { ChangelistID = p4.findPendingChangelistIDByDesc(desc, p4scm.getClientName()); } p4.versionFile(file, publish, ChangelistID, p4scm.isAutoSubmitOnChange()); } } 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(); // check path ends with '/...' if(!depotPath.endsWith("/...")) { depotPath = depotPath.endsWith("/") ? depotPath + "..." : depotPath + "/..."; } // quote path it it has spaces if(depotPath.contains(" ")) { depotPath = "\"" + depotPath + "\""; } Jenkins j = Jenkins.getInstance(); String rootPath = j.getRootDir().getCanonicalPath(); String view = ViewMapHelper.getClientView(depotPath, clientName, true); WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, "", "LOCAL", view, null, null, null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("utf8", false, clientName, spec, false); workspace.setExpand(new HashMap<>()); workspace.setRootPath(rootPath); return new ClientHelper(Jenkins.getInstance(), credential, listener, workspace); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#16 | 28770 | Paul Allen |
Check Item is PerforceScm.DescriptorImpl onChange event. JENKINS-68378 |
||
#15 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#14 | 25668 | Paul Allen |
Merge pull request #94 from lystor/bug-56414 JENKINS-56414: Support of Reconcile with Modtime in P4Publish |
||
#13 | 25564 | Paul Allen |
Merge branch 'local_map' MultiBranch support for 'HelixBranches' local and remote Mappings. Allows MultiBranches to map Depot paths external to the MultiBranch projects root. For example, a MultiBranch project with the following Jenkinsfiles: ProjA >> main //depot/projA/main/Jenkinsfile //depot/projA/main/src/... ProjA>> dev //depot/projA/dev/Jenkinsfile //depot/projA/dev/src/... An 'Includes' path for Branch Sources set to: //depot/projA/... Jenkins will now create two branches 'main' and 'dev'. The default Mapping is '...' so the 'src/...' and any other files under the branch root will appear in the project's workspace. To import an extenal location we can add another line to the mapping: ... //depot/external/stuff/... Now both branches 'main' and 'dev' will have a folder 'depot/external/stuff' with the mapped files. We can also use the `BRANCH_NAME` environment variable in the remote path uses the branch name. ... //depot/external/${BRANCH_NAME}/... and in 'main' you will now see the remote files in ' depot/external/main' along with the local project files mapped with '...' |
||
#12 | 24488 | Paul Allen |
Min version Jenkins 2.60.3 Upgrade dependencies and move to Java 8. |
||
#11 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#10 | 24459 | Paul Allen | View Mapping code cleanup. | ||
#9 | 24403 | Paul Allen |
Support spaces in depot path for MultiBranch and DepotSource JENKINS-52604 |
||
#8 | 23258 | Paul Allen | Clean up a few minor warnings. | ||
#7 | 23239 | Paul Allen |
Add configuration parameter for choosing whether to allow auto-submission of config changes to perforce. This can avoid creating floods of changelists at the cost of requiring a manual changelist submit. A scheduled task may be alleviate the need to manually submit the updated changes while still reducing the number of changelists created. @Tsaukpaetra https://swarm.workshop.perforce.com/reviews/23186 |
||
#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 |