简体   繁体   English

如何通过Java程序在Jenkins中调用“执行Maven版本”?

[英]How to call “Perform Maven release” in Jenkins from a Java program?

I am writing a little java program to perform the complete release of a complex code organization. 我正在编写一个Java程序来执行复杂代码组织的完整发布。 In short, my program needs to release ("Perform Maven release") a project "ProjectA" THROUGH Jenkins . 简而言之,我的程序需要通过Jenkins发布(“ Perform Maven发布”)项目“ ProjectA”。 Then once this release process is finished and successful, the program will detect the new version number generated. 然后,一旦此发行过程完成并成功完成,程序将检测生成的新版本号。 Then it will update this new version number into the properties of the pom files of the other projects (say "ProjectB" and "ProjectC" that are depending on that ProjectA, and commit this modified files in SVN. Then my program will trigger the "perform maven release" job on Projects B and C. 然后,它将新版本号更新到其他依赖于该ProjectA的项目(例如“ ProjectB”和“ ProjectC”)的pom文件的属性中,并在SVN中提交此修改后的文件。然后,我的程序将触发“在项目B和C上执行Maven发布”工作。

I precise that I want the release process to be executed inside/by Jenkins, because I want to have the traces of these actions in the history... I don't want to use directly the "maven-release-plugin" (outside Jenkins), because there would be not trace in the history of Jenkins builds... 我精确地说,我希望在Jenkins内部/由Jenkins执行释放过程,因为我想在历史上了解这些动作的痕迹...我不想直接使用“ maven-release-plugin”(外部詹金斯(Jenkins),因为在詹金斯(Jenkins)建物的历史上没有痕迹...

For this I need to call the action "Perform Maven release" available in Jenkins from this Java program. 为此, 我需要从该Java程序中调用Jenkins中可用的操作“ Perform Maven release”。 How can I do that? 我怎样才能做到这一点? (I've coded already all the other steps). (我已经对所有其他步骤进行了编码)。

During my tests, I managed to call the "Build" job which is 'pure' Jenkins like this: 在测试期间,我设法将“纯” Jenkins称为“构建”作业,如下所示:

WindowsCommandLineExecutor windowsCommandLineExecutor = new WindowsCommandLineExecutor();
int exitCode = windowsCommandLineExecutor.execCmd("java -jar lib/jenkins-cli.jar -s http://MyJenkinsUrl.com:1234/ build \"MyProjectName\" -s --username MyJenkinsUserName --password MyJenkinsPassword", true);

but the "Perform Maven release" job (if I'm not wrong) is available in Jenkins only because we integrated the plugin "Maven-release-plugin", it's not a 'pure' Jenkins job (out-of-the-box)... This explains I guess why there isn't any command such as "performRelease" in this JenkinsCLI tool: http://javadoc.jenkins-ci.org/?hudson/cli/CLICommand.html . 但是“ Perform Maven release”作业(如果我没错的话)仅在Jenkins中可用,这是因为我们集成了插件“ Maven-release-plugin”,这不是“纯粹的” Jenkins作业(开箱即用) )...这解释了我猜为什么在此JenkinsCLI工具中没有诸如“ performRelease”之类的命令: http ://javadoc.jenkins-ci.org/?hudson/cli/CLICommand.html。

Any idea, any advice? 任何想法,任何建议?

One option is to use an HTTP Post to the the Jenkins job as documented here Trigger Maven Release Remotely 一种选择是使用HTTP发布到Jenkins作业,如此处所述远程触发Maven版本

I just documented how to do this from one Jenkins job to another, so you can also refer to this post for more details Trigger "perform maven release" of a jenkins job from another job 我刚刚记录了如何从一个詹金斯工作转移到另一个工作,因此您也可以参考这篇文章以了解更多详细信息从另一个工作触发詹金斯工作的“执行Maven发布”

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

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