package org.jenkinsci.plugins.p4.asset; import hudson.EnvVars; import hudson.Extension; import hudson.FilePath; import hudson.Launcher; import hudson.model.Result; import hudson.model.TaskListener; import hudson.model.AbstractProject; import hudson.model.Run; import hudson.security.ACL; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Notifier; import hudson.tasks.Publisher; import hudson.util.ListBoxModel; import java.io.IOException; import java.util.List; import java.util.logging.Logger; import jenkins.model.Jenkins; import jenkins.tasks.SimpleBuildStep; import org.acegisecurity.Authentication; import org.jenkinsci.plugins.p4.credentials.P4StandardCredentials; import org.jenkinsci.plugins.p4.publish.Publish; import org.jenkinsci.plugins.p4.tasks.PublishTask; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.kohsuke.stapler.DataBoundConstructor; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.domains.DomainRequirement; public class AssetNotifier extends Notifier implements SimpleBuildStep { private static Logger logger = Logger.getLogger(AssetNotifier.class .getName()); private final String credential; private final Workspace workspace; private final Publish publish; public String getCredential() { return credential; } public Workspace getWorkspace() { return workspace; } public Publish getPublish() { return publish; } @DataBoundConstructor public AssetNotifier(String credential, Workspace workspace, Publish publish) { this.credential = credential; this.workspace = workspace; this.publish = publish; } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } @Override public void perform(Run<?, ?> run, FilePath buildWorkspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { // return early if publish not required if (publish.isOnlyOnSuccess() && run.getResult() != Result.SUCCESS) { return; } Workspace ws = (Workspace) workspace.clone(); try { EnvVars envVars = run.getEnvironment(listener); ws.setExpand(envVars); ws.setRootPath(buildWorkspace.getRemote()); String desc = publish.getDescription(); desc = ws.getExpand().format(desc, false); publish.setExpandedDesc(desc); } catch (IOException e) { e.printStackTrace(); } // Create task PublishTask task = new PublishTask(publish); task.setListener(listener); task.setCredential(credential); task.setWorkspace(ws); buildWorkspace.act(task); } public static DescriptorImpl descriptor() { return Jenkins.getInstance().getDescriptorByType( AssetNotifier.DescriptorImpl.class); } @Extension public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> { @Override public boolean isApplicable(Class<? extends AbstractProject> jobType) { return true; } @Override public String getDisplayName() { return "Perforce: Publish assets"; } /** * Credentials list, a Jelly config method for a build job. * * @return A list of Perforce credential items to populate the jelly * Select list. */ public ListBoxModel doFillCredentialItems() { ListBoxModel list = new ListBoxModel(); Class<P4StandardCredentials> type = P4StandardCredentials.class; Jenkins scope = Jenkins.getInstance(); Authentication acl = ACL.SYSTEM; DomainRequirement domain = new DomainRequirement(); List<P4StandardCredentials> credentials; credentials = CredentialsProvider.lookupCredentials(type, scope, acl, domain); if (credentials.isEmpty()) { list.add("Select credential...", null); } for (P4StandardCredentials c : credentials) { StringBuffer sb = new StringBuffer(); sb.append(c.getDescription()); sb.append(" ("); sb.append(c.getUsername()); sb.append(":"); sb.append(c.getP4port()); sb.append(")"); list.add(sb.toString(), c.getId()); } return list; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#5 | 14892 | Sven Erik Knop |
Add p4publish as the last p4 step puzzle piece. Interesting snippet: node { p4sync credential: '634a31d2-bd60-4c39-bf84-b09f057c5431', template: 'jenkins' p4tag rawLabelDesc: 'Jenkins post-build label - from DSL!.', rawLabelName: 'jenkins-{BUILDTAG}' publisher = [$class: 'SubmitImpl', description: 'Submitted by Jenkins. Build: ${BUILD_TAG}', onlyOnSuccess: false, reopen: false] buildWorkspace = [$class: 'StreamWorkspaceImpl', charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}', pinHost: false, streamName: '//stream/main'] p4publish credential: '634a31d2-bd60-4c39-bf84-b09f057c5431', publish: publisher, workspace: buildWorkspace } Makes it easier to read. |
||
#4 | 14071 | Sven Erik Knop | Merging using sknop.p4jenkins-main | ||
#3 | 13760 | Sven Erik Knop | merged changes from main | ||
#2 | 13620 | Sven Erik Knop | Merge changes from Paul's latest release | ||
#1 | 12955 | Sven Erik Knop | Branching using sknop.p4jenkins-main | ||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/asset/AssetNotifier.java | |||||
#6 | 11334 | Paul Allen |
Remote slave support for Publish Perforce Publish commands need to be executed from the remote slave. - Includes refactoring into task package |
||
#5 | 11258 | Paul Allen |
Minor fix for Publish Asset Set client root for new workspaces. Flush client to populate have list (sync -k) |
||
#4 | 11249 | Paul Allen | Fix: Use cloned workspace not config. | ||
#3 | 11246 | Paul Allen | Create/Update client when using publish assets. | ||
#2 | 11236 | Paul Allen | Merge minor GitHub edit | ||
#1 | 11231 | Paul Allen |
Publish assets to Perforce. New feature to allow Jenkins to shelve or submit the build result to Perforce. Configured as a Post Build Step, the Perforce credential and workspace are required as the asset could be published to a different Perforce instance. |