File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\jenkins\model\CoreEnvironmentContributor.java.html

1 package jenkins.model;
2
3 import hudson.EnvVars;
4 import hudson.Extension;
5 import hudson.Util;
6 import hudson.model.Computer;
7 import hudson.model.EnvironmentContributor;
8 import hudson.model.Executor;
9 import hudson.model.Node;
10 import hudson.model.Run;
11 import hudson.model.TaskListener;
12 import jenkins.model.Jenkins.MasterComputer;
13
14 import java.io.IOException;
15
16 /**
17 * {@link EnvironmentContributor} that adds the basic set of environment variables that
18 * we've been exposing historically.
19 *
20 * @author Kohsuke Kawaguchi
21 */
22 @Extension(ordinal=-100)
23 public class CoreEnvironmentContributor extends EnvironmentContributor {
24 @Override
25 public void buildEnvironmentFor(Run r, EnvVars env, TaskListener listener) throws IOException, InterruptedException {
26 Computer c = Computer.currentComputer();
27 if (c!=null){
28 EnvVars compEnv = c.getEnvironment().overrideAll(env);
29 env.putAll(compEnv);
30 }
31
32 Jenkins j = Jenkins.getInstance();
33 String rootUrl = j.getRootUrl();
34 if(rootUrl!=null) {
35 env.put("JENKINS_URL", rootUrl);
36 env.put("HUDSON_URL", rootUrl); // Legacy compatibility
37 env.put("BUILD_URL", rootUrl+r.getUrl());
38 env.put("JOB_URL", rootUrl+r.getParent().getUrl());
39 }
40
41 String root = j.getRootDir().getPath();
42 env.put("JENKINS_HOME", root);
43 env.put("HUDSON_HOME", root); // legacy compatibility
44
45 Thread t = Thread.currentThread();
46 if (t instanceof Executor) {
47 Executor e = (Executor) t;
48 env.put("EXECUTOR_NUMBER", String.valueOf(e.getNumber()));
49 if (e.getOwner() instanceof MasterComputer) {
50 env.put("NODE_NAME", "master");
51 } else {
52 env.put("NODE_NAME", e.getOwner().getName());
53 }
54 Node n = e.getOwner().getNode();
55 if (n != null)
56 env.put("NODE_LABELS", Util.join(n.getAssignedLabels(), " "));
57 }
58 }
59 }
60