簡體   English   中英

如何在 Azure DevOps 管道中將空格傳遞給 maven 目標

[英]How to pass spaces to maven goal in Azure DevOps pipeline

我嘗試使用參數-Dmessage="update parent pom"scm:checkin目標執行 Maven。 這在我的本地機器上運行順利,但是當我嘗試在 Azure DevOps YAML 管道中使用Maven 任務運行它時,它失敗了。

- task: Maven@3
  inputs:
    mavenPomFile: pom.xml
    goals: clean verify scm:checkin -Dmessage="update parent pom"

在管道的 output 中,它正確地說將執行以下命令:

/usr/share/maven/bin/mvn -f /__w/45/s/pom.xml clean verify scm:checkin -Dmessage="update parent pom"

但是,該命令的執行就像沒有空格一樣,並且單詞parent被假定為另一個 maven 目標,而不是消息的一部分。 以下日志摘錄顯示scm:checkin目標已成功執行,並且應執行另一個名為parent的目標:

...
[INFO] 
[INFO] ---------------------------< example:project >--------------------------
[INFO] Building example project 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-scm-plugin:2.0.0-M1:checkin (default-cli) @ project ---
[INFO] Executing: /bin/sh -c cd '/__w/45/s' && 'git' 'rev-parse' '--show-prefix'
[INFO] Working directory: /__w/45/s
[INFO] Executing: /bin/sh -c cd '/__w/45/s' && 'git' 'status' '--porcelain' '.'
[INFO] Working directory: /__w/45/s
[INFO] 
[INFO] ---------------------------< example:project >--------------------------
[INFO] Building example project 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12.784 s
[INFO] Finished at: 2022-01-28T20:14:44Z
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "parent". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException
The process '/usr/share/maven/bin/mvn' failed with exit code 1

我嘗試了引號、雙引號、帶反斜杠的 escaping 的各種組合,僅針對字符串和整個 YAML 值,但結果始終相同。

對於Azure Pipelines中的Maven任務,需要分別給出目標和選項。 (輸入甚至被稱為goals ,這可能表明它不是用於選項)。

以下 yaml 定義將按問題運行 Maven:

- task: Maven@3
  inputs:
    mavenPomFile: pom.xml
    goals: clean verify scm:checkin
    options: -Dmessage="update parent pom"

管道中的 output 現在按選項優先排序:

/usr/share/maven/bin/mvn -f /__w/45/s/pom.xml -Dmessage="update parent pom" clean verify scm:checkin

我通常避免使用 CLI 包裝的 Azure DevOps 任務,並在我的管道中使用以下示例腳本來執行 maven。 希望這對您也有幫助。

- script: |
    mvn clean verify -f pom.xml scm:checkin -Dmessage="update parent pom"
  displayName: Run Maven clean verify
  workingDirectory: [where pom file is]

暫無
暫無

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

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