Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to specify the pom.xml path in jenkins pipeline script

my maven project looks like below working dir Jenkins error

this is how my script looks like

node {
    stage ('Build') {
        git url: 'https://github.com/rakshitha2/test_proj.git'

        def mvnHome = tool 'M3'

        bat "${mvnHome}\\bin\\mvn -B install"
    }
}

I have to go inside parent directory and execute maven command in Jenkins pipeline script. I tried specifying POM path in MVN command its giving me an error saying "path is unexpected at this time". but the same is working in my local.

I'm new to Jenkins and groovy. kindly help me with this.

like image 612
thakshira Avatar asked Jan 03 '23 21:01

thakshira


2 Answers

As it is basically a normal maven mechanism. So

 sh 'mvn -f otherdirectory/pom.xml clean install'
like image 66
keiki Avatar answered Jan 06 '23 14:01

keiki


pipeline {
    agent any
    tools {
        maven 'mavenHome'
        jdk 'JavaHome'
    }
    stages {
        stage('Build') {
            steps {
                echo 'maven clean'
                //ABC indicates the folder name where the pom.xml file resides
                bat ' mvn -f ABC/pom.xml clean install'  
            }
            post {
                success {
                    echo 'Now Archiving'
                }
            }
        }
    }
}
like image 30
lohita Avatar answered Jan 06 '23 15:01

lohita