package org.jenkinsci.plugins.p4.build; import hudson.EnvVars; import hudson.Extension; import hudson.model.Descriptor; import hudson.model.EnvironmentContributor; import hudson.model.Run; import hudson.model.TaskListener; import hudson.scm.SCM; import jenkins.model.Jenkins; import org.apache.commons.lang.StringUtils; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.review.P4Review; import org.jenkinsci.plugins.p4.tagging.TagAction; import java.io.IOException; import java.util.Map; @Extension() public class P4EnvironmentContributor extends EnvironmentContributor { @Override public void buildEnvironmentFor(Run run, EnvVars env, TaskListener listener) throws IOException, InterruptedException { TagAction tagAction = TagAction.getLastAction(run); buildEnvironment(tagAction, env); } public static void buildEnvironment(TagAction tagAction, Map<String, String> map) { // parts of Jenkins passes EnvVars as Map<String,String> EnvVars env = new EnvVars(map); buildEnvironment(tagAction, env); map.putAll(env); } private static void buildEnvironment(TagAction tagAction, EnvVars env) { if (tagAction == null) { return; } // Set P4_CHANGELIST value if (tagAction.getRefChanges() != null) { String change = tagAction.getRefChange().toString(); env.put("P4_CHANGELIST", change); } // Set P4_CLIENT workspace value if (tagAction.getClient() != null) { String client = tagAction.getClient(); env.put("P4_CLIENT", client); } // Set P4_PORT connection if (tagAction.getPort() != null) { String port = tagAction.getPort(); env.put("P4_PORT", port); } // Set P4_USER connection if (tagAction.getUser() != null) { String user = tagAction.getUser(); env.put("P4_USER", user); } // Set P4_REVIEW connection if (tagAction.getReview() != null) { P4Review review = tagAction.getReview(); env.put("P4_REVIEW", review.getId()); env.put("P4_REVIEW_TYPE", review.getStatus().toString()); } // Set P4_TICKET connection Jenkins j = Jenkins.getInstance(); if (j != null) { @SuppressWarnings("unchecked") Descriptor<SCM> scm = j.getDescriptor(PerforceScm.class); PerforceScm.DescriptorImpl p4scm = (PerforceScm.DescriptorImpl) scm; if (tagAction.getTicket() != null && !p4scm.isHideTicket()) { String ticket = tagAction.getTicket(); env.put("P4_TICKET", ticket); } } // JENKINS-37442: Make the log file name available if(tagAction.getChangelog() != null) { String changelog = tagAction.getChangelog().getAbsolutePath(); changelog = StringUtils.defaultIfBlank(changelog, "Not-set"); env.put("HUDSON_CHANGELOG_FILE", changelog); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#15 | 26208 | Paul Allen |
Merge pull request #112 from p4charu/jenkinsci-master JENKINS-60141: Refactored to reduce number of calls to login -s |
||
#14 | 25123 | Paul Allen |
Added Pipeline Job support and tests for declarative and scripted. JENKINS-39107 |
||
#13 | 25115 | Paul Allen |
Merge pull request #91 from p4charu/jenkinsci-master Fixed JENKINS-39107 and JENKINS-55826 |
||
#12 | 24850 | Paul Allen |
Merge pull request #83 from rudolfwalter/patch-1 Avoid unnecessary call to TagAction.getTicket() |
||
#11 | 24574 | Paul Allen |
Merge pull request #77 from kroutley/master [JENKINS-53221] Add P4_ROOT to environment variables |
||
#10 | 23018 | Paul Allen |
Support null changelogFile if checkout sets changelog:false JENKINS-46352 |
||
#9 | 22987 | Paul Allen |
Clean up changelogFilename reporting for HUDSON_CHANGELOG_FILE. JENKINS-37442 |
||
#8 | 22986 | Paul Allen |
Copy environment map to EnvVars. JENKINS-37584 |
||
#7 | 22944 | Paul Allen | Bug fixes for Swarm and update Environment Helpers. | ||
#6 | 22926 | Paul Allen |
Expose P4_REVIEW and P4_REVIEW_STATUS. Extended test coverage and removed duplicate code for building the environment. |
||
#5 | 22317 | Paul Allen | Find changelog file for Pipeline builds and add to HUDSON_CHANGELOG_FILE environment. | ||
#4 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#3 | 21372 | Paul Allen |
Support custom SyncID. Exclude BUILD_NUMBER from SyncID. Pushed logging to higher level, so it is not reporting TagActions when building the Environment. JENKINS-40460 |
||
#2 | 21207 | Paul Allen |
Multi client support in Pipeline. If two or more `p4sync` operations are called in one Pipeline script, they MUST have different client names. During a build, multiple entries are added to the build history; on subsequent builds they are used in the three following situations: - Polling: largest change number across all the checkouts is used. - Change Summary: last change with the same client name is used. - Environment: last change recorded (regardless of client). Added two test cases to cover basic multi sync build/poll situations. JENKINS-38401 JENKINS-37462 JENKINS-39652 |
||
#1 | 21133 | Paul Allen |
P4 Environment Variables for pipeline. JENKINS-37584 |