package org.jenkinsci.plugins.p4.tasks; import hudson.FilePath.FileCallable; import hudson.model.Descriptor; import hudson.model.Item; import hudson.model.Run; import hudson.model.TaskListener; import hudson.remoting.VirtualChannel; import hudson.scm.SCM; import jenkins.model.Jenkins; import jenkins.security.Roles; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.PerforceScm.DescriptorImpl; import org.jenkinsci.plugins.p4.changes.P4ChangeRef; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.populate.ForceCleanImpl; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.RoleSensitive; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.logging.Logger; public class RemoveClientTask extends AbstractTask implements FileCallable<Boolean>, Serializable { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(RemoveClientTask.class.getName()); private boolean deleteClient; private boolean deleteFiles; public RemoveClientTask(String credential, Run<?, ?> run, TaskListener listener) { super(credential, run, listener); useGlobalSettings(); } public RemoveClientTask(String credential, Item project, TaskListener listener) { super(credential, project, listener); useGlobalSettings(); } public void setDeleteClient(boolean deleteClient) { this.deleteClient = deleteClient; } public void setDeleteFiles(boolean deleteFiles) { this.deleteFiles = deleteFiles; } private void useGlobalSettings() { Jenkins j = Jenkins.getInstance(); @SuppressWarnings("unchecked") Descriptor<SCM> scm = j.getDescriptor(PerforceScm.class); DescriptorImpl p4scm = (DescriptorImpl) scm; if (p4scm != null) { deleteClient = p4scm.isDeleteClient(); deleteFiles = p4scm.isDeleteFiles(); } } @Override public Object task(ClientHelper p4) throws Exception { logger.info("Task: remove client."); String client = getClientName(); try { p4.log("P4 Task: cleanup client: " + client); // remove files if required if (deleteFiles) { ForceCleanImpl forceClean = new ForceCleanImpl(true, true, null, null); p4.log("P4 Task: unsyncing client: " + client); logger.info("P4: unsyncing client: " + client); p4.syncFiles(new P4ChangeRef(0), forceClean); // TODO: Jenkins should do this, uncomment if needed. // File root = workspace.getCanonicalFile(); // FileUtils.forceDelete(root); } // remove client if required if (deleteClient) { if (p4.isClient(client)) { // revert any pending files, before deleting client p4.revertAllFiles(false); p4.log("P4 Task: remove client: " + client); logger.info("P4: remove client: " + client); p4.deleteClient(client); } else { logger.warning("P4: Cannot find: " + client); return deleteFiles; } } } catch (Exception e) { logger.warning("P4: Not able to get connection"); return false; } return deleteFiles; } @Override public Boolean invoke(File workspace, VirtualChannel channel) throws IOException, InterruptedException { return (Boolean) tryTask(); } @Override public void checkRoles(RoleChecker checker) throws SecurityException { checker.check((RoleSensitive) this, Roles.SLAVE); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#14 | 25736 | Paul Allen |
Cleanup step - use checkbox state and ignore Global option. The global options for deleting the client is ignored and the cleanup checkbox state is used. The Global option for deleting files still applies, but some what irrelevant as Jenkins can manage this in other steps. Note that the RemoveClientTask is used for cleaning up temp clients in polling and checkout steps as wall as deleting a Jenkins Job. JENKINS-47107 |
||
#13 | 24777 | Paul Allen |
Global Library to use UUID for client name and delete after use. Add a new 'Delete the Perforce Client after checkout' option (for Manual clients) which normaly is false, but set to true for Global Library checkouts. JENKINS-50975 |
||
#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 | 22821 | Paul Allen |
Merge pull request #53 from jenkinsci/TagAction-order Get Last TagAction. JENKINS-37618 JENKINS-45613 |
||
#9 | 22315 | Paul Allen |
Pending change cleanup for unshelve. Unshelve would leave files open for add/edit/delete, the 'tidy' option will 'revert -k' the files leaving the content in the workspace, but removing the 'have' list data. Unshelve can now specify a Credential and Workspace, important for situations where more than one sync occurs in a pipeline script. JENKINS-43430 |
||
#8 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#7 | 22021 | Paul Allen |
Set environment to expand client name for Publish and Remove Client. JENKINS-43378 |
||
#6 | 19764 | Paul Allen | Simplify RemoveClientTask by using AbstractTask. | ||
#5 | 19752 | Paul Allen | Remove 'modtime' option from ForceClean | ||
#4 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#3 | 19324 | Paul Allen |
Added Parallel Sync. An Advanced Populate option. Must specify the PATH to the ‘p4’ executable as parallel sync is not supported by p4java. JENKINS-29228 |
||
#2 | 19090 | Paul Allen |
Revert files before deleting a Workspace. JENKINS-24070 Jenkins Log (successful delete): Apr 21, 2016 10:08:20 PM org.jenkinsci.plugins.p4.PerforceScm processWorkspaceBeforeDeletion INFO: processWorkspaceBeforeDeletion Apr 21, 2016 10:08:20 PM org.jenkinsci.plugins.p4.tasks.RemoveClientTask invoke INFO: Task: remove client. Apr 21, 2016 10:08:20 PM org.jenkinsci.plugins.p4.tasks.RemoveClientTask invoke INFO: P4: unsyncing client: jenkins-master-open Apr 21, 2016 10:08:20 PM org.jenkinsci.plugins.p4.tasks.RemoveClientTask invoke INFO: P4: remove client: jenkins-master-open Apr 21, 2016 10:08:20 PM org.jenkinsci.plugins.p4.PerforceScm processWorkspaceBeforeDeletion INFO: clean: true |
||
#1 | 18335 | Paul Allen |
Slave support for Clean Up Workspace. Will remove the client and/or versioned files. Other non versioned files are removed by Jenkins not the p4 plugin. Uncomment lines 67,68 in RemoveClientTask.java to fix Jenkins bug. JENKINS-24003 |