【问题标题】:How to pass spaces to maven goal in Azure DevOps pipeline如何在 Azure DevOps 管道中将空格传递给 Maven 目标
【发布时间】:2022-01-28 20:37:10
【问题描述】:

我尝试使用参数-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 值的组合,但结果始终相同。

【问题讨论】:

    标签: maven azure-devops azure-pipelines


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回答。这确实有效,但是我发现了 Maven 任务的问题并将其添加为答案。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-30
      • 1970-01-01
      • 2021-08-09
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      相关资源
      最近更新 更多