How to insert Jenkins environment variable into maven assembly?

I need to get some Jenkins environment variables, such as BUILD_NUMBER and BUILD_URL, and enter them as variables in my Java Maven assembly.

I added this to pom.xml

<properties>
    <jenkins.buildUrl>${env.BUILD_URL}</jenkins.buildUrl>
</properties>

and when creating only with mvn installation, I try to get a variable

private static final String JENKINS_BUILD_URL = System.getProperty("jenkins.buildUrl");

but unfortunately the result is null ...

What am I doing with the wrong guys?

+4
source share
2 answers

Guess you are trying to read this value in your unit tests? Then you will need to configure the surefire plugin environment variables:

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-surefire-plugin</artifactId>
   <configuration>
       <environmentVariables>
           <jenkins.buildUrl>${env.BUILD_URL}</jenkins.buildUrl>
       </environmentVariables>
   </configuration>
</plugin>

: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#environmentVariables

, , , Maven Tomcat Plugin.

+4

pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>      
    <jenkins.buildNumber>${env.BUILD_NUMBER}</jenkins.buildNumber>      
</properties>

.properties

jenkins.build.number = ${jenkins.buildNumber}

maven,

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
    </resource>
</resources>

java,

properties.load(MyClass.class.getResourceAsStream("/project.properties"));
version = properties.getProperty("jenkins.build.number");

maven -Denv.BUILD_NUMBER = ${BUILD_NUMBER}

.

+4

All Articles