Skip to content
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 PATH for 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 of tool or withMaven wrappers.

How to Fix It

1. Install Maven on the agent

sudo apt update && sudo apt install maven -y

2. 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

What is the Jenkins 'tool' directive?
The tools directive in Declarative Pipeline automatically downloads and configures the specified tool (Maven, JDK, Gradle) on the agent. It adds the tool to PATH for the duration of the pipeline.
How do I check which Java version Maven uses?
Run mvn --version on the agent. Maven requires JDK — ensure the JAVA_HOME environment variable points to a valid JDK installation.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro