如何在Azure DevOps管道中将空间传递给maven目标



我尝试使用参数-Dmessage="update parent pom"执行Maven以实现scm:checkin目标。这在我的本地机器上运行得很顺利,但当我试图在Azure DevOps YAML管道中使用Maven任务运行时,它失败了。

- 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值,但结果总是一样的。

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

我通常避免使用包装在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]

相关内容

最新更新