我正在尝试为我的maven发布插件配置SCM。然而,问题是:我的原型中的pom.xml,我不想硬编码单个scm变量,而是参数化版本。在我的jenkinsfile中,我们有一个填充scm url的专有工具,所以我想在从我的原型设置项目后将该url替换为我的pom.xml。请参阅下面的代码段。
<developerConnection>scm:git:${myVariable}</developerConnection>
在我的Jenkins文件中,我将这个值拉出(这可以正常工作):
node {
stage 'Checkout'
checkout scm
def myVariable= sh(returnStdout: true, script: 'git config remote.origin.url').trim()
那么,回顾一下,我想知道Jenkins的值如何被替换为pom.xml?
现在,我收到了这个错误:
[INFO] fetch url: ${myVariable}
[INFO] push url: ${myVariable}
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.755 s
[INFO] Finished at: 2017-07-17T16:21:00+00:00
[INFO] Final Memory: 20M/784M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:prepare (default-cli) on project newSeedService: An error is occurred in the checkin process: Exception while executing SCM command. JGit checkin failure! ${myVariable}: not found. -> [Help 1]
谢谢
答案 0 :(得分:0)
如果要从项目POM中隔离这些属性,可以使用属性文件,则必须使用Properties Maven插件,并在Maven的初始化阶段运行它的读取项目属性目标生命周期。插件页面中的示例在此处再现:
<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0-alpha-2</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>etc/config/dev.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
</plugins>