简体   繁体   中英

Unable to set maven in groovy script

I am using groovy script in jenkins pipeline job and I need maven to execute my stage.

I do not have control of .profile as it is running on slave. I need to set the Maven in my groovy script so that I can run man clean compile .

maven is located at /opt/runtime/apache-maven-3.3.3/bin/mvn.

I am very new to groovy and want to know how to use this.

You can do something like this:

// Maven location
def mvnHome = tool name: 'maven 3_3_9', type: 'hudson.tasks.Maven$MavenInstallation'
env.MAVEN_HOME = mvnHome

// Begin Compile
stage concurrency: 1, name: 'compile'
sh '''${MAVEN_HOME}/bin/mvn clean compile'''

Please note that the tool name comes from the Maven configuration you have defined in the Global Tool Configuration page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM