简体   繁体   English

如何使用 groovy 脚本运行 maven 命令

[英]How to run maven command using groovy script

I am using maven verison 3.3.9 on linux-version: "4.4.0-43-generic".我在 linux 版本上使用 Maven 版本 3.3.9:“4.4.0-43-generic”。 For somehow i can run the maven command using this way on console:不知何故,我可以在控制台上使用这种方式运行 maven 命令:

 mvn -pl '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed' -P compileWithGradle,nightly,flex-debug clear

double quotes inside the single quote i dont know the reason but it is working this way on console.单引号内的双引号我不知道原因,但它在控制台上以这种方式工作。 I have a jenkins pipline in which i want to use this command but it is not working eiter i use:我有一个 jenkins pipline,我想在其中使用此命令,但它无法正常工作,但我使用的是:

sh ''' mvn -pl '"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed"' -P compileWithGradle,nightly,flex-debug clear '''

OR use :或使用:

 sh """ mvn -pl '"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed"' -P compileWithGradle,nightly,flex-debug clear """

result will be given in a "!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" OR '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed'结果将在"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" OR '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed'

Can someone tell me a proper way to use in jenkins script or inside a maven goal.有人可以告诉我在 jenkins 脚本中或在 maven 目标中使用的正确方法。

You can use你可以使用

sh 'mvn -pl "!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" -P compileWithGradle,nightly,flex-debug clear'

It should work.它应该工作。

If bash shell is used you have to escape !.如果使用 bash shell,则必须转义 !。 with a backslash \\ .带有反斜杠\\ This works.这有效。

mvn -pl \!com.mycom.hp.comp:zonegtools

Ah , but this is not working in Jenkins groovy code.(2 backslashes)啊,但这在 Jenkins 常规代码中不起作用。(2 个反斜杠)

sh "mvn  -pl \\!com.mycom.hp.comp:zonegtools"

This does not work in jenkins+ groovy + maven这在 jenkins+ groovy + maven 中不起作用

MVN error: Could not find the selected project in the reactor: !com.mycom.hp.comp:zonegtools MVN 错误:在反应堆中找不到选定的项目:!com.mycom.hp.comp:zonegtools

I can run mvn command in the groovy file like this.我可以像这样在 groovy 文件中运行 mvn 命令。 Could you try this?你能试试这个吗?

run('mvn install:install-file -Dhttps.protocols=TLSv1.2 -DgroupId=com.sample-DartifactId=sample -Dversion=2.1.0 -Dpackaging=jar -Dfile=src/main/lib/sample-2.1.0.jar -DgeneratePom=true -Dmaven.test.skip=true')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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