Perforce plugin: making $JOB_NAME available to p4 command

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Perforce plugin: making $JOB_NAME available to p4 command

Jos Backus
    Hi,

In an attempt to run a build step (mounting a sandbox from a LUN) before
checkout, I'm trying to wrap the p4 command specified by 'Path to p4
executable' in the Perforce plugin UI. The idea is to detect whether the
sandbox is mounted and if not, mount it before invoking the real p4 command.

For this to work we need info about the job, which we can access through
$JOB_NAME, but unfortunately Hudson/the Perforce plugin doesn't seem export
$JOB_NAME into the environment of the p4 command at that time.

I tried the following patch:

--- a/src/main/java/hudson/plugins/perforce/PerforceSCM.java
+++ b/src/main/java/hudson/plugins/perforce/PerforceSCM.java
@@ -374,6 +374,8 @@ public class PerforceSCM extends SCM {
         }
 
         env.put("P4CLIENT", getEffectiveClientName(build));
+        LOGGER.warning("Setting $JOB_NAME to: " + build.getProject().getFullName());
+        env.put("JOB_NAME", build.getProject().getFullName());
         PerforceTagAction pta = getMostRecentTagAction(build);
         if (pta != null) {
             if (pta.getChangeNumber() > 0) {

But env doesn't appear to be directly related to the environment of the p4
command, as the wrapper doesn't see the JOB_NAME environment variable.

How would I go about exporting $JOB_NAME into the p4 command's environment?

Thanks,
Jos

P.s.: A better way to accomplish what I want seems to be to use the
prepareWorkspace mechanism, but it looks to be more work, so I thought I'd
investigate this approach first.

--
Jos Backus
jos at catnook.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]