我用
调用maven通过jenkins开始发布过程-Dresume=false clean release:prepare release:perform
因为我想在准备过程完成之前更改源代码(添加目录和文件并将它们提交给git),我想只在发布:准备阶段运行配置文件'doAtPrepare'。配置文件已经在正确的地方工作,但不幸的是调用了两次。一次在发布阶段:准备,一次在发布阶段:执行。后者在git上提交到"分离的头"时会产生一个错误。
对于在release:perform阶段运行配置文件,在maven-release-plugin中只有配置选项'releaseProfiles'有效。但我需要反过来,到目前为止还没有找到解决方案。
我尝试了profile.activation.properties (profile=!doAtPrepare),尝试设置变量(-D)并使用profile.activation检查它们。属性,尝试检查profile.activation.file中的现有文件(这不起作用,因为文件名包含${version}参数),尝试在jenkins命令行中使用-P(它在两个阶段触发配置文件)等等。
有谁能帮我找到一个可行的解决方案吗?我找到了一个变通方法,但不是真正的解决方案。我们仍然欢迎更好的建议。
首先,添加一个执行所需任务的配置文件:
<profile>
<id>createNextDir</id>
<build>
<plugins>
<plugin>
<!-- whatever you want -->
</plugin>
</plugins>
</build>
</profile>
接下来,在配置文件中添加一个作业,该作业将在目标目录中创建一个具有固定文件名的虚拟文件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>createNextDir1</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<propertyfile file="target/done.lock" comment="Version ${project.version}">
</propertyfile>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
</plugin>
最后一步是仅在文件不存在时激活配置文件。请注意,在release:perform期间,基本目录是target/checkout/yourproject,因此需要引用正确的文件../../../yourproject/target/done.lock
<profile>
<id>createNextDir</id>
<activation>
<file>
<missing>../../../yourproject/target/done.lock</missing>
</file>
</activation>
<!-- Rest of profile -->
</profile>