package org.jenkinsci.plugins.p4.unshelve; import hudson.Extension; import hudson.FilePath; import hudson.Launcher; import hudson.model.AbstractBuild; import hudson.model.AbstractProject; import hudson.model.BuildListener; import hudson.model.Run; import hudson.model.TaskListener; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Builder; import hudson.util.ListBoxModel; import hudson.util.ListBoxModel.Option; import jenkins.model.Jenkins; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.tasks.UnshelveTask; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.kohsuke.stapler.DataBoundConstructor; import java.io.IOException; import java.util.logging.Logger; public class UnshelveBuilder extends Builder { private final String shelf; private final String resolve; private final boolean tidy; private final boolean ignoreEmpty; private static Logger logger = Logger.getLogger(UnshelveBuilder.class.getName()); @DataBoundConstructor public UnshelveBuilder(String shelf, String resolve, boolean tidy, boolean ignoreEmpty) { this.shelf = shelf; this.resolve = resolve; this.tidy = tidy; this.ignoreEmpty = ignoreEmpty; } @Deprecated public UnshelveBuilder(String shelf, String resolve, boolean tidy) { this(shelf, resolve, tidy, false); } @Deprecated public UnshelveBuilder(String shelf, String resolve) { this(shelf, resolve, false, false); } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } public String getShelf() { return shelf; } public String getResolve() { return resolve; } public boolean isTidy() { return tidy; } public boolean isIgnoreEmpty() { return ignoreEmpty; } @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) { AbstractProject<?, ?> project = build.getParent(); PerforceScm p4scm = PerforceScm.convertToPerforceScm(project.getScm()); if (p4scm != null) { String credential = p4scm.getCredential(); Workspace workspace = p4scm.getWorkspace(); FilePath buildWorkspace = build.getWorkspace(); try { if (buildWorkspace == null) { return false; } return unshelve(build, credential, workspace, buildWorkspace, listener); } catch (IOException e) { logger.warning("Unable to Unshelve"); e.printStackTrace(); } catch (InterruptedException e) { logger.warning("Unable to Unshelve"); e.printStackTrace(); } } return false; } protected boolean unshelve(Run<?, ?> run, String credential, Workspace workspace, FilePath buildWorkspace, TaskListener listener) throws IOException, InterruptedException { // Setup Unshelve Task UnshelveTask task = new UnshelveTask(resolve, tidy); task.setListener(listener); task.setCredential(credential, run.getParent()); // Set workspace used for the Task Workspace ws = task.setEnvironment(run, workspace, buildWorkspace); // Expand shelf ${VAR} as needed and set as LABEL String id = ws.getExpand().format(shelf, false); // If settings are set to do nothing if changelist is empty just return true. if (ignoreEmpty && (id == null || id.isEmpty())) { logger.warning("Shelf list ID is empty or null, we will be skipping this task."); return true; } long change = Long.parseLong(id.trim()); task.setShelf(change); task.setWorkspace(ws); return buildWorkspace.act(task); } public static DescriptorImpl descriptor() { Jenkins j = Jenkins.getInstance(); if (j != null) { return j.getDescriptorByType(UnshelveBuilder.DescriptorImpl.class); } return null; } @Extension @Symbol("unshelve") public static class DescriptorImpl extends BuildStepDescriptor<Builder> { @Override @SuppressWarnings("rawtypes") public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; } @Override public String getDisplayName() { return "Perforce: Unshelve"; } public static ListBoxModel doFillResolveItems() { return new ListBoxModel(new Option("Resolve: None", "none"), new Option("Resolve: Safe (-as)", "as"), new Option("Resolve: Merge (-am)", "am"), new Option("Resolve: Force Merge (-af)", "af"), new Option("Resolve: Yours (-ay) -- keep your edits", "ay"), new Option("Resolve: Theirs (-at) -- keep shelf content", "at")); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#16 | 29321 | Paul Allen |
Merge pull request #165 from skumar7322/UnshelveIssue Unable to unshelve change: java.lang.IllegalStateException: Expected 1 instance of hudson.model.User$AllUsers but got 0 JENKINS-69172 When unshelve task is executed on a slave node, then Jenkins.getInstance() can not be used, hence no user is found while updating the changelog. |
||
#15 | 24488 | Paul Allen |
Min version Jenkins 2.60.3 Upgrade dependencies and move to Java 8. |
||
#14 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#13 | 24484 | Paul Allen |
Trim white space from shelve ID. JENKINS-52970 |
||
#12 | 22914 | Paul Allen | (minor) Update Unshelve step from int to long. | ||
#11 | 22859 | Paul Allen | Missing changes from #54 | ||
#10 | 22858 | Paul Allen |
Merge pull request #54 from mihailogazda/master. P4Unshelve build step can now be skipped successfully if the changelist ID is not set. |
||
#9 | 22684 | Paul Allen | Added @Symbol to Extension classes for Pipeline Syntax. | ||
#8 | 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 |
||
#7 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#6 | 20593 | Paul Allen |
Unshelve options in Pipeline. Update merge options and support unshelve ListBoxModel Option in Pipeline. |
||
#5 | 20246 | Paul Allen |
Convert merge options for unshelve to ListBoxModel Option (from basic jelly) @atiniir |
||
#4 | 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 |
||
#3 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#2 | 16529 | Paul Allen |
DSL for Unshelve task. DSL example: p4unshelve resolve: 'at', shelf: '10831' |
||
#1 | 16514 | Paul Allen |
Unshelve and resolve build step. Implements a classic Jenkins Build step (i.e. not Workflow). Must provide a shelf change number and resolve options. The shelf change number supports variable expansion ${VAR}. |