[英]Unable to set maven in groovy script
I am using groovy script in jenkins pipeline job and I need maven to execute my stage.我在 jenkins 管道作业中使用 groovy 脚本,我需要 maven 来执行我的阶段。
I do not have control of .profile as it is running on slave.我无法控制 .profile,因为它在从站上运行。 I need to set the Maven in my groovy script so that I can run man clean compile
.我需要在我的 groovy 脚本中设置 Maven,以便我可以运行man clean compile
。
maven is located at /opt/runtime/apache-maven-3.3.3/bin/mvn. maven 位于 /opt/runtime/apache-maven-3.3.3/bin/mvn。
I am very new to groovy and want to know how to use this.我对 groovy 很陌生,想知道如何使用它。
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.请注意,工具名称来自您在全局工具配置页面中定义的 Maven 配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.