-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
docker-pipeline 1.14 and below
Problem description and workarounds
Problem Description
Takari's "mvnw" don't work with docker-pipeline and the "maven" image because docker-pipeline don't honor the Docker image entrypoint.
The Docker image "maven" is having a collision of environment variables with Takari's "mvnw" using the environment variable "MAVEN_CONFIG" for a different thing:
- "MAVEN_CONFIG" is used in Takari's "mvnw" to pass command line parameters (e.g. "-
show-version" or "-settings path/to/settings.xml") - "MAVEN_CONFIG" is used in the Docker image "maven" to locate the Maven "user home" (i.e. "${user.home}/.m2")
csanchez has mitigated this problem on the Docker image "maven" unsetting the "MAVEN_CONFIG" environment variable in the Docker image entrypoint (see here).
Unfortunately, as the Jenkins Docker Pipeline is no longer honoring the Docker image entrypoint since v1.8 (see JENKINS-41316), the "MAVEN_CONFIG" is defined in the build agent execution environment with a value that is not compatible with "mvnw".
node("linux-agent-with-docker") { docker.image('maven:3.5.2-jdk-8').inside { git 'https://github.com/takari/maven-wrapper.git' // begin the sh step with "env &&" for troubleshooting, no need in real life sh 'env && ./mvnw effective-settings' } }
Started by user anonymous [Pipeline] node Running on my-agent in /path/to/workspace/docker-pipeline-mvnw [Pipeline] { [Pipeline] sh [docker-pipeline-mvnw] Running shell script + docker inspect -f . maven:3.5.2-jdk-8 . [Pipeline] withDockerContainer my-agent does not seem to be running inside a container $ docker run -t -d -u 1000:1000 -w /path/to/workspace/docker-pipeline-mvnw -v /path/to/workspace/docker-pipeline-mvnw:/path/to/workspace/docker-pipeline-mvnw:rw,z -v /path/to/workspace/docker-pipeline-mvnw@tmp:/path/to/workspace/docker-pipeline-mvnw@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat maven:3.5.2-jdk-8 [Pipeline] { [Pipeline] git > git rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository > ... > git rev-list f6cdada0869ff31c7f981f40e2cfefdd375ad7eb # timeout=10 [Pipeline] sh [docker-pipeline-mvnw] Running shell script + env JENKINS_HOME=/opt/jenkins-oss/jenkins_home ... MAVEN_CONFIG=/root/.m2 + ./mvnw help:effective-settings [INFO] Scanning for projects... [INFO] ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.589 s [INFO] Finished at: 2017-11-06T15:51:21Z [INFO] Final Memory: 7M/22M [INFO] ------------------------------------------------------------------------ [ERROR] Unknown lifecycle phase "/root/.m2". 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] ... [Pipeline] } $ docker stop --time=1 2a714af59ccce59a3f6f0fc2d1bded685468490dcd2eb4c89ebf39a81c04e336 $ docker rm -f 2a714af59ccce59a3f6f0fc2d1bded685468490dcd2eb4c89ebf39a81c04e336 [Pipeline] // withDockerContainer [Pipeline] ... ERROR: script returned exit code 1 Finished: FAILURE
Workarounds
Using the Docker image "openjdk" instead of "maven"
As Takari's "mvnw" installs the JVM, no need to use a Docker image "maven".
node("linux-agent-with-docker") { docker.image('jdk-8').inside { git 'https://github.com/takari/maven-wrapper.git' // begin the sh step with "env &&" for troubleshooting, no need in real life sh 'env && ./mvnw effective-settings' } }
Unsetting "MAVEN_CONFIG"
Unset the "MAVEN_CONFIG" environment variable in the "sh" steps before invoking "mvnw"
node("linux-agent-with-docker") { docker.image('maven').inside { git 'https://github.com/takari/maven-wrapper.git' // begin the sh step with "env &&" for troubleshooting, no need in real life sh 'unset MAVEN_CONFIG && env && ./mvnw effective-settings' } }
Wrapping the call to "mvnw" in a "withMaven" step (requires "withMaven" version 3.0.3+)
"withMaven" version 3.0.3+ sets the "MAVEN_CONFIG" with the Maven parameters defined for the Pipeline Maven Plugin and with sensible defaults.
node("linux-agent-with-docker") { docker.image('maven').inside { git 'https://github.com/takari/maven-wrapper.git' withMaven (...) { // begin the sh step with "env &&" for troubleshooting, no need in real life sh 'env && ./mvnw effective-settings' } } }
- is related to
-
JENKINS-41316 docker.image('my-image').inside{...} no longer honors Dockerfile "entrypoint" since version 1.8
- Reopened
- links to