如何在 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 时,它失败了。

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

在管道的输出中,它正确地指出将执行以下命令:

/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

我尝试了引号、双引号、反斜杠转义的各种组合,仅针对字符串和整个 YAML 值,但结果始终相同。

我通常避免在 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]

对于Azure Pipelines 中的Maven 任务,需要单独给出目标和选项。 (输入甚至被称为 goals,这可能表明它不是用于选项)。

下面的 yaml 定义将 运行 Maven 作为问题:

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

管道中的输出现在按选项优先排序:

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