簡體   English   中英

從Jenkinsfile將變量注入pom.xml

[英]Injecting a variable into pom.xml from Jenkinsfile

我正在嘗試為我的Maven發布插件配置SCM。 但是,問題是:在我的原型中,pom.xml我不想對單個scm變量進行硬編碼,而是對參數化版本進行硬編碼。 在我的jenkinsfile中,我們有一個專有工具來填充scm url,因此一旦我從原型設置項目后,就想將該URL替換為pom.xml。 請參見下面的代碼段。

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

謝謝

如果要將這些屬性與項目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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM