Configure Maven Options in Jenkins

I am experimenting with Jenkins, and I am looking for a way to allow Jenkins to set parameters for different projects. Typically, all of these attributes are stored in the settings.xml file (I currently have a settings.xml file for the user running Jenkins, which includes the default properties and my repositories).

I want to have different assemblies of the same project that define different Maven options, as well as different goals. (you have work that often performs compilation checks, one that deploys the application to the test server every hour, another to free up to the stage, and then prod)

What is the best way to create parameterized assemblies in Jenkins?

+14
maven parameters build jenkins
Feb 27 2018-12-12T00:
source share
1 answer

There are several options for you. Here is what I use:

Create profiles in your assembly.

<profile> <activation> <file> <exists>findbugs-exclude.xml</exists> </file> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <configuration> <excludeFilterFile>findbugs-exclude.xml</excludeFilterFile> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>package</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <includeScope>runtime</includeScope> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile> 

You can define in jenkins clean install -P package - for the package task or clean install for normal build

Put the parameters directly in pom from the command line:

Call Maven:

 mvn clean install -Dparameter.one=ONE -Dparameter.two=TWO 

POM:

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.test</groupId> <artifactId>test</artifactId> <version>1.0.0</version> <name>test</name> <properties> <testng.version>6.4</testng.version> </properties> <dependencies> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>${testng.version}</version> <scope>test</scope> </dependency> </dependencies> </project> 

If you run it, then testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1 testng version 6.3.1 will be used.

Cm

Download: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.pom Downloaded: http://repo.maven.apache.org/maven2/org /testng/testng/6.3.1/testng-6.3.1.pom (0 B at 0.0 KB / sec) Download: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1 /testng-6.3.1.jar Downloaded: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.jar (0 B at 0.0 KB / sec)

You can parameterize the standard pom part (directly set default values ​​and override them using runtime properties)

Finally, you can use the environment variables Parameterized Build or Parameterized Trigger Plugin

Edit in the latest sample version:

 <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>${env.testngVersion}</version> <scope>test</scope> </dependency> 

In bash, you can call:

 export testngVersion=6.0 mvn clean install 

Or in jenkins by setting testngVersion = 6.0 in the This build is parameterized section

+18
Feb 28 '12 at 8:30
source share




All Articles