1
votes

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

3
Is apache-maven installed on the machine? Try mvn --version from the command line.Dezso Gabos
@DezsoGabos thanks I think that was an issue , but after installing maven error has changed now but still get it The goal you specified requires a project to execute but there is no POM in this directory (/var/lib/jenkins/workspace/vcc). Please verify you invoked Maven from the correct directory.ArsalanK
@ArsalanK well... is there a pom in that directory?Federico klez Culloca
Make sure after you checkout from the SCM you change to the directory in the workspace where your pom.xml is.Dezso Gabos
@ArsalanK Your original question seems to be solved. If you have a different problem, please open a new question.J Fabian Meier

3 Answers

1
votes

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"
   }
}
0
votes

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"
  }
}
0
votes

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.

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"
        }
    }
}