package org.jenkinsci.plugins.p4.tagging; import hudson.model.Run; import hudson.scm.AbstractScmTagAction; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import com.perforce.p4java.client.IClientViewMapping; import com.perforce.p4java.core.ILabelMapping; import com.perforce.p4java.core.ViewMap; import com.perforce.p4java.impl.generic.client.ClientView; import com.perforce.p4java.impl.generic.core.Label; import com.perforce.p4java.impl.generic.core.Label.LabelMapping; public class TagAction extends AbstractScmTagAction { private String tag; private List<String> tags = new ArrayList<String>(); private String credential; private String client; private Object buildChange; public TagAction(Run<?, ?> run) { super(run); } public String getIconFileName() { if (!getACL().hasPermission(PerforceScm.TAG)) return null; return "/plugin/p4/icons/label.gif"; } public String getDisplayName() { if (isTagged()) return "Perforce Label"; else return "Label This Build"; } @Override public boolean isTagged() { return tags != null && !tags.isEmpty(); } public void doSubmit(StaplerRequest req, StaplerResponse rsp) throws Exception, ServletException { getACL().checkPermission(PerforceScm.TAG); String description = req.getParameter("desc"); String name = req.getParameter("name"); labelBuild(name, description); rsp.sendRedirect("."); } public void labelBuild(String name, String description) throws Exception { tag = name; ClientHelper p4 = new ClientHelper(credential, null, client); Label label = new Label(); label.setDescription(description); label.setName(name); label.setRevisionSpec("@" + buildChange); // set label view to match workspace ViewMap<ILabelMapping> viewMapping = new ViewMap<ILabelMapping>(); ClientView view = p4.getClientView(); for (IClientViewMapping entry : view) { String left = entry.getLeft(); LabelMapping lblMap = new LabelMapping(); lblMap.setLeft(left); viewMapping.addEntry(lblMap); } label.setViewMapping(viewMapping); // save label if (!tags.contains(name)) { tags.add(name); getRun().save(); } // update Perforce p4.setLabel(label); p4.disconnect(); } public void setBuildChange(Object buildChange) { this.buildChange = buildChange; } public Object getBuildChange() { return buildChange; } public String getClient() { return client; } public String getPort() { ConnectionHelper p4 = new ConnectionHelper(credential, null); String p4port = p4.getPort(); p4.disconnect(); return p4port; } public void setCredential(String credential) { this.credential = credential; } public void setClient(String client) { this.client = client; } public String getTag() { return tag; } public List<String> getTags() { return tags; } /** * Method used by Jelly code to show Label information (do not remove) * * @param tag * @return * @throws Exception */ public Label getLabel(String tag) throws Exception { ClientHelper p4 = new ClientHelper(credential, null, client); Label label = p4.getLabel(tag); return label; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 14132 | Sven Erik Knop | Tagging works from the workflow, URL for the tag object still broken. | ||
#2 | 13760 | Sven Erik Knop | merged changes from main | ||
#1 | 12955 | Sven Erik Knop | Branching using sknop.p4jenkins-main | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/tagging/TagAction.java | |||||
#10 | 12931 | Paul Allen |
#review-12907 @mjoubert Added P4PORT to env for command line calls. |
||
#9 | 11626 | Paul Allen |
Workflow support. - Updated the plugin to the latest LTS Jenkins release 1.580.3. - Updated P4Java to 2014.1 Tested with simple ‘static’ workspace, there may be limitations with ‘manual’ workspace. Plan to add DSL support by extending the SCMStep class. #review-11537 JENKINS-24206 |
||
#8 | 11084 | Paul Allen |
(mjoubert) Fully populate changelog.xml Replaces sparse change log which only recorded the change number. The change is now recorded in full allowing faster page load times. The number of files listed in the change is limited to 50; to view larger changes please add a repo browser such as Swarm, Fisheye, P4Web, etc… |
||
#7 | 9986 | Paul Allen | Re-added getLabel method used by Jelly. | ||
#6 | 9984 | Paul Allen |
Set P4_CHANGELIST to change for Automatic Labels. P4_CHANGELIST is set to a change number or label if defined in Populate as pinned or a build parameter. |
||
#5 | 9851 | Paul Allen | Merging using p4-jenkins | ||
#4 | 9819 | Paul Allen | Merging using p4-jenkins | ||
#3 | 9769 | Paul Allen | Copying using p4-jenkins | ||
#2 | 9696 | Paul Allen | Updated install notes and removed old ref to p4-client | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/tagging/TagAction.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/tagging/TagAction.java | |||||
#3 | 9126 | Paul Allen | Added Perforce label icon to TagAction. | ||
#2 | 9077 | Paul Allen |
Added support for automatic Labels as a post-build Action. Ported original code for promoted builds, but not tested. |
||
#1 | 9069 | Paul Allen |
Adding initial support for tagging Jenkins builds as Perforce Automatic Labels. Only implements TagAction (manual labels); TagNotifier and test cases TODO. |