I am using Jenkins with Testswarm and this plugin (forked sources).
I want to get a "job name" for Testswarm containing the Jenkins job name, build number and svn revision number.
Putting JOB_NAME in the configuration field does not help, the variable is not replaced by its value.
So I modified the plugin source code to get the Jenkins environment variables but all I get are "null"s.
Here is the culprit code. (in src/main/java/com/javaclimber/jenkins/testswarmplugin/TestSwarmBuilder.java from line 205)
I researched a lot concerning this functionnality and I did not find a working example for getting a variable.
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
...
EnvVars envVars = build.getEnvironment(listener);
...
envVars.get("JOB_NAME")
}
I am not at ease in Java and I am stuck at this point. Any idea anyone, please ?
Update: java used version
java version "1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1~10.04.2)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Replacing
EnvVars envVars = build.getEnvironment(listener);
By
EnvVars envVars = new EnvVars();
envVars = build.getEnvironment(listener);
did the trick...
What version of Java are you using? According to this, to get an environment variable, you need to add the following:
String job_name = System.getenv("JOB_NAME");
Have you tried this instead?
Also, I'm not sure what the configuration field looks like, but did you try using $JOB_NAME
instead of JOB_NAME
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With