Jenkins: mvn: command not found
Jenkins: mvn: command not found
DodaTech
2 min read
The Jenkins error “mvn: command not found” appears in build logs when a build step tries to run Maven but the mvn binary is not available on the Jenkins agent.
What It Means
Jenkins executed a shell step that called mvn, but the Maven executable is not installed on the agent machine or not included in the agent’s PATH. Maven automation depends on the mvn CLI being available.
Why It Happens
- Maven is not installed on the Jenkins agent.
- Maven is installed but not added to the
PATHfor the Jenkins user. - The agent is a minimal container or ephemeral pod without build tools.
- The Jenkins global tool configuration for Maven is set up but the tool is not referenced in the job.
- The job uses
sh 'mvn clean install'instead oftoolorwithMavenwrappers.
How to Fix It
1. Install Maven on the agent
sudo apt update && sudo apt install maven -y2. Use Jenkins Global Tool Configuration
Manage Jenkins → Tools → Add Maven → Set name and version.
Then in your pipeline:
pipeline {
tools {
maven 'Maven-3.9' // matches the name in Global Tool Configuration
}
stages {
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}3. Use a Docker agent with Maven
pipeline {
agent {
docker { image 'maven:3.9-eclipse-temurin-17' }
}
stages {
stage('Build') {
steps {
sh 'mvn clean install'
}
}
}
}4. Run Maven from a custom path
sh '/opt/apache-maven-3.9.6/bin/mvn clean install'FAQ
Previous
Exception in thread 'main' java.lang.ArrayIndexOutOfBoundsException
Next
MongoDB: E11000 duplicate key error collection
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro