Issue
I try to execute Maven with the parameter -Dmessage="update parent pom"
for the scm:checkin
goal. This works smoothly on my local machine, however when I try to get this running with the href="https://docs.microsoft.com/de-de/azure/devops/pipelines/tasks/build/maven?view=azure-devops" rel="nofollow noreferrer">Maven task in Azure DevOps YAML pipelines it fails.
- task: Maven@3
inputs:
mavenPomFile: pom.xml
goals: clean verify scm:checkin -Dmessage="update parent pom"
In the output of the pipeline it correctly says the following command will be executed:
/usr/share/maven/bin/mvn -f /__w/45/s/pom.xml clean verify scm:checkin -Dmessage="update parent pom"
However, the command is executed as if without spaces and the word parent
is assumed to be another maven goal instead of being part of the message. The following extract from the log shows that the scm:checkin
goal is executed succesfully and another goal named parent
should be executed:
...
[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
I have tried various combinations of quotes, double quotes, escaping with backslashes, for the string only and the whole YAML value, but the result is always the same.
Solution
For the Maven task in Azure Pipelines the goals and options need to be given separately. (The input is even called goals
which could have indicated that it's not for options).
The following yaml definition will run Maven as in the question:
- task: Maven@3
inputs:
mavenPomFile: pom.xml
goals: clean verify scm:checkin
options: -Dmessage="update parent pom"
The output in the pipeline is now sorted with options first:
/usr/share/maven/bin/mvn -f /__w/45/s/pom.xml -Dmessage="update parent pom" clean verify scm:checkin
Answered By - kap
Answer Checked By - David Marino (JavaFixing Volunteer)