I need to get some of the Jenkins environment variables like BUILD_NUMBER and BUILD_URL and to inject them as variables in my Maven Java build.
I have added this to the pom.xml
<properties>
<jenkins.buildUrl>${env.BUILD_URL}</jenkins.buildUrl>
</properties>
and while building with just mvn install I'm trying to get the variable by
private static final String JENKINS_BUILD_URL = System.getProperty("jenkins.buildUrl");
but unfortunately the result is null...
What I'm doing wrong guys?
Guessing you are trying to read this value into your unit tests? Then you would have to configure the environment variables of the surefire plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<jenkins.buildUrl>${env.BUILD_URL}</jenkins.buildUrl>
</environmentVariables>
</configuration>
</plugin>
As stated in this documentation: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#environmentVariables
Note that it's possible to do the same in other plugin, like the Maven Tomcat Plugin for example.
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