简体   繁体   English

如何通过代码重新运行参数化 Jenkins 作业(不通过 UI 使用重建插件)?

[英]How to re-run Parameterized Jenkins Job again via code (without using rebuild plugin through UI)?

I have 80 jenkins jobs which I want to re-build programmatically.我有 80 个 jenkins 工作,我想以编程方式重新构建它们。 All 80 were run with different set of parameters.所有 80 个都使用不同的参数集运行。 I can see 2 approaches here for job x which is inside a view as well as folder,我可以在这里看到 2 种方法,用于在视图和文件夹中的作业 x,

  1. Use some Jenkins API to build x job just by specifying the job id(aka job_url)for x job仅通过为 x 作业指定作业 id(又名 job_url),使用一些 Jenkins API 来构建 x 作业
  2. Traverse and find out parameters of the x job and use Jenkins API to build x job using those parameters.遍历并找出 x 作业的参数,并使用 Jenkins API 使用这些参数构建 x 作业。
  3. Some Groovy Script (I have no experience writing this)一些 Groovy 脚本(我没有写这个的经验)

Rebuild plugin is something which essentially does 1) but I want to do the same via code.重建插件本质上是 1) 但我想通过代码做同样的事情。 Please suggest specific solution if possible instead of generic API links.如果可能,请建议具体的解决方案,而不是通用的 API 链接。 I have gone through all XML, JSON and Python API for Jenkins but there isn't one straightforward way I could find.我已经浏览了 Jenkins 的所有 XML、JSON 和 Python API,但我找不到一种直接的方法。 Thanks.谢谢。

After trying for a while, I was able to come up with a groovy script which upon running in jenkins-server-url/script does the trick.尝试了一段时间后,我想出了一个 groovy 脚本,它在jenkins-server-url/script中运行时可以解决问题

The script is hosted at https://github.com/nirzari/groovy-scripts/blob/master/rebuild.groovy该脚本托管在https://github.com/nirzari/groovy-scripts/blob/master/rebuild.groovy

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

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