[英]Releasing from Nexus staging repository via Jenkins/Maven
我有一個Java項目。 有些部分是jar
文件,有些是war
文件。 我還有Jenkins和Nexus Pro,當團隊中的開發人員提交SVN時,Jenkins構建會自動啟動。
使用Maven版本插件,我能夠mvn versions:set -DnewVersion=1.0.$SVN_REVISION
作為預構建步驟,然后mvn clean test deploy
。 在這個過程結束時,我有一個my-artifact-1.0.1234.jar
上傳到我的Nexus Pro Staging Repository。
由於我們在CI類型的環境中工作,我們可能會有一百個(或更多)分段構建。 當時機成熟時,QA團隊希望將某個構建推廣到“后期”環境(想想QA,或SIT等等。環境在這里更像是一個鎖定狀態。)
我想要的工作流程如下:
我已經知道我可以從命令行執行此操作,並且它正在工作:
mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus
mvn nexus-staging:rc-release -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus -DstagingRepositoryId=abcd-1000 -Ddescription="Release from CLI."
我遇到的問題是你必須在命令行上指定stagingRepositoryId
。 我怎么能完成這個?
我正在做的是解析輸出
mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus
然后只需將您需要的存儲庫與您的特定邏輯相匹配。 對我來說使用python是最好的解決方案(但你可以用任何語言自己完成):
output = subprocess.check_output("mvn nexus-staging:rc-list -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus")
for line in output.split('\n'):
if "repo" in line:
stagingRepositoryId = "repo-" + line[8:23]
考慮輸出為
[INFO] repo_qa-3514 OPEN Implicitly created (auto staging).
[INFO] repo_qa-3518 Implicitly created (auto staging).
[INFO] repo_qa-3521 OPEN Implicitly created (auto staging).
[INFO] repo-2011 OPEN Implicitly created (auto staging).
您將在解析后運行第二個命令:
mvn nexus-staging:rc-release -DserverId=nexus -DnexusUrl=http://my.nexus.ip:8081/nexus -DstagingRepositoryId=repo-2011 -Ddescription="Release from CLI."
我認為通過使用SNAPSHOT和發布存儲庫可以輕松實現您要做的事情。 因此,您在SNAPSHOT構建中進行正常開發,一旦准備好進行測試,就可以創建一個標記構建,從POM中的版本中刪除SNAPSHOT。 所有這一切都可以使用jenkins和Nexus來實現。
此外,您不需要在您的版本中使用SVN修訂版號,而是可以通過發布插件管理增量版本號。
總結一下:
以上所有步驟均使用Maven發布插件自動執行,並通過jenkins作業運行。
我的工作有以上設置。
OP表示'SNAPSHOT'不在圖片中。 在這種情況下,這篇文章回答了這個問題: 自動部署到sonatype的oss maven存儲庫 [看第二個答案]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.