mavenjenkinsgroovyjenkins-pipeline

Jenkins pipeline error: Tool type maven does not have an install


I'm using Groovy script to deploy application to server. I want to install latest version of Maven before project gets built using below script.

    pipeline {
      agent any

      tools {
          maven "Maven 3.6.3"    
      }
      ....
      stages {
      ....
      }
    }

I get this below exception when I run the job.

Running in Durability level: MAX_SURVIVABILITY org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 15: Tool type "maven" does not have an install of "Maven 3.6.3" configured - did you mean "Maven-3.3.3"? @ line 15, column 15. maven "Maven 3.6.3"

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
    at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
    at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
    at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:428)
Finished: FAILURE

Can anyone suggest what I'm making wrong?


Solution

  • I tried the below steps and it worked for me.

    1. Goto Dashboard > Manage Jenkins > Global Tools Configuration. Then, click on Add Maven and mentioned a name and maven version. In my case, I named it as 3.8.5.

    Apply the changes

    enter image description here

    In the pipeline code, mentioned tools { maven 'NAME_AS_IN_GLOBAL_CONFIGURATION' }

    pipeline {
        agent { label 'main' }
        
    
        tools {
            maven '3.8.5' 
           // This is the name as in Global Configuration
        }
        // ... stages ...///
    }