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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Tom Huybrechts
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.model;
25
26 import java.util.Locale;
27
28 import hudson.EnvVars;
29 import jenkins.model.Jenkins;
30 import org.kohsuke.stapler.DataBoundConstructor;
31 import org.kohsuke.stapler.export.Exported;
32
33 public class RunParameterValue extends ParameterValue {
34
35 private final String runId;
36
37 @DataBoundConstructor
38 public RunParameterValue(String name, String runId, String description) {
39 super(name, description);
40 this.runId = runId;
41 }
42
43 public RunParameterValue(String name, String runId) {
44 super(name, null);
45 this.runId = runId;
46 }
47
48 public Run getRun() {
49 return Run.fromExternalizableId(runId);
50 }
51
52 public String getRunId() {
53 return runId;
54 }
55
56 @Exported
57 public String getJobName() {
58 return runId.split("#")[0];
59 }
60
61 @Exported
62 public String getNumber() {
63 return runId.split("#")[1];
64 }
65
66
67 /**
68 * Exposes the name/value as an environment variable.
69 */
70 @Override
71 public void buildEnvVars(AbstractBuild<?,?> build, EnvVars env) {
72 String value = Jenkins.getInstance().getRootUrl() + getRun().getUrl();
73 env.put(name, value);
74
75 env.put(name + ".jobName", getJobName()); // undocumented, left for backward compatibility
76 env.put(name + "_JOBNAME", getJobName()); // prefer this version
77
78 env.put(name + ".number" , getNumber ()); // same as above
79 env.put(name + "_NUMBER" , getNumber ());
80
81 env.put(name.toUpperCase(Locale.ENGLISH),value); // backward compatibility pre 1.345
82
83 }
84
85 @Override
86 public String getShortDescription() {
87 return "(RunParameterValue) " + getName() + "='" + getRunId() + "'";
88 }
89
90 }
91