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.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 static Logger logger = Logger.getLogger(UnshelveBuilder.class.getName()); @DataBoundConstructor public UnshelveBuilder(String shelf, String resolve, boolean tidy) { this.shelf = shelf; this.resolve = resolve; this.tidy = tidy; } @Deprecated public UnshelveBuilder(String shelf, String resolve) { this(shelf, resolve, false); } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } public String getShelf() { return shelf; } public String getResolve() { return resolve; } public boolean isTidy() { return tidy; } @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); int change = Integer.parseInt(id); 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 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 | |
---|---|---|---|---|---|
#2 | 22326 | Paul Allen | Merging down using p4-jenkins | ||
#1 | 21940 | Paul Allen | Branching using p4-jenkins | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/unshelve/UnshelveBuilder.java | |||||
#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}. |