簡體   English   中英

如何使用 groovy 腳本運行 maven 命令

[英]How to run maven command using groovy script

我在 linux 版本上使用 Maven 版本 3.3.9:“4.4.0-43-generic”。 不知何故,我可以在控制台上使用這種方式運行 maven 命令:

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

單引號內的雙引號我不知道原因,但它在控制台上以這種方式工作。 我有一個 jenkins pipline,我想在其中使用此命令,但它無法正常工作,但我使用的是:

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

或使用:

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

結果將在"!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed" OR '!com.mycom.hp.comp:zonegtools,!com.mycom.hpe:testbed'

有人可以告訴我在 jenkins 腳本中或在 maven 目標中使用的正確方法。

你可以使用

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

它應該工作。

如果使用 bash shell,則必須轉義 !。 帶有反斜杠\\ 這有效。

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

啊,但這在 Jenkins 常規代碼中不起作用。(2 個反斜杠)

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

這在 jenkins+ groovy + maven 中不起作用

MVN 錯誤:在反應堆中找不到選定的項目:!com.mycom.hp.comp:zonegtools

我可以像這樣在 groovy 文件中運行 mvn 命令。 你能試試這個嗎?

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