Jenkins - mvn not found

亡梦爱人 提交于 2020-06-28 06:07:06

问题


Hello I'm new to jenkins and getting this issue. I'm using jenkins in windows azure

  • mvn clean package /var/lib/jenkins/workspace/vcc@tmp/durable-b5407f14/script.sh: 2: /var/lib/jenkins/workspace/vcc@tmp/durable-b5407f14/script.sh: mvn: not found.

Jenkinsfiles:

node {
   stage('init') {
      checkout scm
   }
   stage('build') {
      sh '''
         mvn clean package
         cd target
         cp ../src/main/resources/web.config web.config
         cp todo-app-java-on-azure-1.0-SNAPSHOT.jar app.jar 
         zip todo.zip app.jar web.config
      '''
   }
   stage('deploy') {
      azureWebAppPublish azureCredentialsId: env.AZURE_CRED_ID,
      resourceGroup: env.RES_GROUP, appName: env.WEB_APP, filePath: "**/todo.zip"
   }
}

can any body help me how can I resolve this mvn issue.

P.S I'm following this tutorial https://docs.microsoft.com/en-us/azure/jenkins/tutorial-jenkins-deploy-web-app-azure-app-service


回答1:


You may try to add maven tool to your pipeline:

 tools {
    maven 'M3'
  }
  stages {
   stage('init') {
      checkout scm
   }
   stage('build') {
      sh '''
         mvn clean package
         cd target
         cp ../src/main/resources/web.config web.config
         cp todo-app-java-on-azure-1.0-SNAPSHOT.jar app.jar 
         zip todo.zip app.jar web.config
      '''
   }
   stage('deploy') {
      azureWebAppPublish azureCredentialsId: env.AZURE_CRED_ID,
      resourceGroup: env.RES_GROUP, appName: env.WEB_APP, filePath: "**/todo.zip"
   }
}



回答2:


I add this line right before sh command in the build stage : def mvnHome = tool name: 'Apache Maven 3.6.0', type: 'maven' and instead of mvn you should use ${mvnHome}/bin/mvn

thank this youtube film to help me.

 pipeline{
  stage('com'){
    def mvnHome = tool name: 'Apache Maven 3.6.0', type: 'maven'
    sh "${mvnHome}/bin/mvn -B -DskipTests clean package"
  }
}



回答3:


You may wanna check if Jenkins has the pipeline-maven plugin installed. If you don't have it, search and install the pipeline-maven plugin.

Once the plugin is installed, you can use maven as follows

node{
    stage('init'){
      //init sample
    }
    stage('build'){
        withMaven(maven: 'mvn') {
            sh "mvn clean package"
        }
    }
}


来源:https://stackoverflow.com/questions/54984408/jenkins-mvn-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!