-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
Kubernetes
Jenkins 2.440.1
pipeline-maven-plugin 1381.v08b_63fa_30559
Updating to latest available version our pipelines stop to work. We run into a k8s container and before this update the step install both JDK and Maven without any issue.
Current log
[Pipeline] container [Pipeline] { [Pipeline] tool [Pipeline] writeFile [Pipeline] tool Unpacking [https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip] to /home/jenkins/agent/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.9 on opensoftwaresrl-os-polcity-integration-pr-12-2-9nkdq-ssdt-wsmnf [Pipeline] withEnv [Pipeline] { [Pipeline] configFileProvider provisioning config files... copy managed file [Artifactory settings.xml] to [file:/home/jenkins/agent/workspace/integration_PR-12@tmp/config5257036906047941027tmp|file:///home/jenkins/agent/workspace/integration_PR-12@tmp/config5257036906047941027tmp] [Pipeline] { [Pipeline] withMaven Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-2-9nkdq-ssdt-wsmnf Executing command: "printenv" "MAVEN_HOME" exit Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-2-9nkdq-ssdt-wsmnf Executing command: "printenv" "M2_HOME" exit Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-2-9nkdq-ssdt-wsmnf Executing command: "/bin/sh" "-c" "which mvn" exit which: no mvn in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin) [withMaven] WARNING: You are running an old version of Maven (UNKNOWN), you should update to at least 3.8.x [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] isUnix [Pipeline] sh + mvn -f pom.xml --batch-mode -t /home/jenkins/agent/workspace/integration_PR-12@tmp/toolchains.xml -ntp -Djava.awt.headless=true -Denforcer.fail=true -Denforcer.skip=false -Dskip-sources=true -DskipTests=true -DskipITs=true -U clean install /home/jenkins/agent/workspace/integration_PR-12@tmp/durable-71195aaa/script.sh.copy: line 1: mvn: command not found
Since it recognize to be run into a container it refuse to install any tool, reading the documentation at https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/FAQ.adoc#how-to-use-the-pipeline-maven-plugin-with-docker does not work because also wrapping the withMaven() block within a withEnv block
def mvnHome = tool "Maven 3.9" withEnv("PATH+M2_HOME=" + mvnHome, "PATH+M2_CMD=${mvnHome}/bin") { withMaven() { sh("mvn build") } }
it appears that the mvn shell script runs with an environment with no variables defined by either withEnv or configFileProvider.
The WithMavenStepExecution2.withContainer variable set to true implies that the Maven pipeline step does not install the specified maven/jdk tools (it is not clear to me why they should not be installed in a container context) BUT it also means that the environment map (EnvVar) is not enriched with those in use by the system and goes into error because it cannot find the mvn command in the PATH.
Working version log:
[Pipeline] configFileProvider provisioning config files... copy managed file [Artifactory settings.xml] to [file:/home/jenkins/agent/workspace/integration_PR-12@tmp/config14195073197983339772tmp|file:///home/jenkins/agent/workspace/integration_PR-12@tmp/config14195073197983339772tmp] [Pipeline] { [Pipeline] withMaven [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] isUnix [Pipeline] sh + set AGENT_WORKDIR=/home/jenkins/agent ... DOCKER_CONFIG=/home/jenkins/agent/workspace/integration_PR-12@tmp/.docker HOME=/home/jenkins/agent JAVA_HOME=/home/jenkins/agent/tools/hudson.model.JDK/JDK_11 JAVA_TOOL_OPTIONS='-Dmaven.ext.class.path="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c" JENKINS_HOME=/var/jenkins_home JOB_BASE_NAME=PR-12 ... M2_HOME=/home/jenkins/agent/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.9 MAVEN_CONFIG='--batch-mode --no-transfer-progress --settings "/home/jenkins/agent/workspace/srl_os-polcity-integration_PR-12@tmp/withMavend356152c/settings.xml" "-Dmaven.repo.local=/home/jenkins/agent/workspace/integration_PR-12@tmp/.m2/repository" ' MAVEN_HOME=/home/jenkins/agent/tools/hudson.tasks.Maven_MavenInstallation/Maven_3.9 MVN_CMD=/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c/mvn MVN_CMD_DIR=/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c MVN_SETTINGS=/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c/settings.xml PATH=/home/jenkins/agent/tools/hudson.model.JDK/JDK_11/bin:/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin POD_CONTAINER=main SETTINGS_XML=/home/jenkins/agent/workspace/integration_PR-12@tmp/config14195073197983339772tmp WORKSPACE=/home/jenkins/agent/workspace/integration_PR-12 WORKSPACE_TMP=/home/jenkins/agent/workspace/integration_PR-12@tmp container=oci + mvn -f pom.xml --batch-mode -t /home/jenkins/agent/workspace/integration_PR-12@tmp/toolchains.xml -ntp -Djava.awt.headless=true -Denforcer.fail=true -Denforcer.skip=false -Dskip-sources=true -DskipTests=true -DskipITs=true -U clean install Picked up JAVA_TOOL_OPTIONS: -Dmaven.ext.class.path="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c" [INFO] [jenkins-event-spy] Generate /home/jenkins/agent/workspace/integration_PR-12@tmp/withMavend356152c/maven-spy-20240314-173157-40711564589951471065362.log.tmp ...
With latest version the console log is
[Pipeline] container [Pipeline] { [Pipeline] tool [Pipeline] writeFile [Pipeline] configFileProvider provisioning config files... copy managed file [Artifactory settings.xml] to [file:/home/jenkins/agent/workspace/integration_PR-12@tmp/config9680854301282812487tmp|file:///home/jenkins/agent/workspace/integration_PR-12@tmp/config9680854301282812487tmp] [Pipeline] { [Pipeline] withMaven WARNING: "withMaven() {...} " step running within a container, tool installations are not available see [https://issues.jenkins-ci.org/browse/JENKINS-36159]. You have specified a JDK installation "JDK 11", which will be ignored. [withMaven] WARNING: Specified Maven 'Maven 3.9' cannot be installed, will be ignored. Step running within a container, tool installations are not available see [https://issues.jenkins-ci.org/browse/JENKINS-36159]. Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-15-bhfng-nv8-xswh2 Executing command: "printenv" "MAVEN_HOME" exit Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-15-bhfng-nv8-xswh2 Executing command: "printenv" "M2_HOME" exit Executing sh script inside container main of pod opensoftwaresrl-os-polcity-integration-pr-12-15-bhfng-nv8-xswh2 Executing command: "/bin/sh" "-c" "which mvn" exit which: no mvn in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin) [withMaven] WARNING: You are running an old version of Maven (UNKNOWN), you should update to at least 3.8.x [Pipeline] { [Pipeline] stage [Pipeline] { (Build) [Pipeline] isUnix [Pipeline] sh + set AGENT_WORKDIR=/home/jenkins/agent DOCKER_CONFIG=/home/jenkins/agent/workspace/integration_PR-12@tmp/.docker HOME=/home/jenkins/agent ... JAVA_TOOL_OPTIONS='-Dmaven.ext.class.path="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMaven72c5de77/pipeline-maven-spy.jar" -Dorg.jenkinsci.plugins.pipeline.maven.reportsFolder="/home/jenkins/agent/workspace/integration_PR-12@tmp/withMaven72c5de77" ' MAVEN_CONFIG='--batch-mode --settings "/home/jenkins/agent/workspace/integration_PR-12@tmp/withMaven72c5de77/settings.xml" "-Dmaven.repo.local=/home/jenkins/agent/workspace/integration_PR-12@tmp/.m2/repository" ' MVN_CMD_DIR=/home/jenkins/agent/workspace/integration_PR-12@tmp/withMaven72c5de77 MVN_SETTINGS=/home/jenkins/agent/workspace/integration_PR-12@tmp/withMaven72c5de77/settings.xml PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin WORKSPACE=/home/jenkins/agent/workspace/integration_PR-12 WORKSPACE_TMP=/home/jenkins/agent/workspace/integration_PR-12@tmp ... container=oci + mvn -f pom.xml --batch-mode -t /home/jenkins/agent/workspace/integration_PR-12@tmp/toolchains.xml -ntp -Djava.awt.headless=true -Denforcer.fail=true -Denforcer.skip=false -Dskip-sources=true -DskipTests=true -DskipITs=true -U clean install /home/jenkins/agent/workspace/integration_PR-12@tmp/durable-e0646e07/script.sh.copy: line 1: mvn: command not found
Note like PATH is missing of contributed path in withEnv and also the SETTINGS_XML env variable contributed by configFileProvider step is missing
I had rollback plugin to version 1376.v18876d10ce9c