有一些适合您的选择。这是我正在使用的:
在构建中创建配置文件。
<profile> <activation> <file> <exists>findbugs-exclude.xml</exists> </file> </activation> <build> <plugins> <plugin> <groupId>org.prehaus.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>您可以在jenkins中定义
clean install -P package-用于打包任务或
clean install正常构建
从命令行将参数直接放入pom:
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>如果正常运行,将使用testng版本6.4。但是,如果您像这样运行它:
mvn clean install-Dtestng.version=6.3.1将使用testng版本6.3.1。
看到
- 下载:http
- :
- //repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.pom下载:
- http
- [//repo.maven.apache.org/maven2/org
- /testng/testng/6.3.1/testng-6.3.1.pom(0](http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.pom)
- B,0.0 KB
- /秒)下载:http
- //repo.maven.apache.org/maven2/org/testng/testng/6.3.1
/testng-6.3.1.jar
下载:http
:
//repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.jar
(0 B,速度为0.0 KB /秒)
您可以参数化pom的默认部分(直接设置默认值并通过执行属性覆盖它)
最后,您可以使用环境变量[Parameterized Build](http://wiki.jenkins-
ci.org/display/JENKINS/Parameterized+Build)或Parameterized Trigger
Plugin
更改上一个示例版本:
<dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>${env.testngVersion}</version> <scope>test</scope></dependency>在bash中,您可以调用:
export testngVersion=6.0mvn clean install
或者在詹金斯中通过在
This build is parameterized部分中设置testngVersion = 6.0



