【问题标题】:Injecting a variable into pom.xml from Jenkinsfile从 Jenkinsfile 将变量注入 pom.xml
【发布时间】:2017-12-22 06:58:04
【问题描述】:

我正在尝试为我的 Maven 发布插件配置 SCM。但是,问题是:我的原型中的 pom.xml,我不想硬编码单个 scm 变量而是参数化版本。在我的 jenkinsfile 中,我们有一个填充 scm url 的专有工具,所以一旦我从我的原型设置项目,我想将该 url 替换到我的 pom.xml 中。请参阅下面的代码 sn-p。

  <developerConnection>scm:git:${myVariable}</developerConnection>

在我的 Jenkinsfile 中,我像这样提取这个值(这工作正常):

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]

谢谢

【问题讨论】:

    标签: maven jenkins


    【解决方案1】:

    如果你想从项目 POM 中隔离这些属性,你可以使用属性文件,你必须使用 Properties Maven 插件,并在 Maven 生命周期的初始化阶段运行它的 read-project-properties 目标。插件页面的示例在此处复制:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2015-03-24
      • 2016-08-14
      • 2022-08-19
      • 1970-01-01
      • 2023-04-05
      相关资源
      最近更新 更多