简体   繁体   English

Jenkins Groovy,Jenkins DSL 脚本

[英]Jenkins Groovy, Jenkins DSL Script

How to change the jenkins job status Manually in pipeline?如何在管道中手动更改詹金斯工作状态?

Example:-例子:-

I have 7 freestyle jobs (A,B,C,D,E,F,G) in Pipeline, job A initial job, after A, we have three parallel test jobs (B,C,D).我在流水线中有 7 个自由式工作(A、B、C、D、E、F、G),工作 A 初始工作,在 A 之后,我们有三个并行测试工作(B、C、D)。 Job E is the report generation job, here we need to implement user interaction for Pipeline will continue or not?.作业E是报表生成作业,这里我们需要实现Pipeline的用户交互是否会继续?。

Conditions at Job E: 1) If Job E is successful, Pipeline will continue to Release 2) if Job E is Failed, Pipeline should be stop here. Job E 的条件: 1) 如果 Job E 成功,Pipeline 将继续发布 2) 如果 Job E 失败,Pipeline 应该在这里停止。 3) if Job E is Unstable, here we need to implement user interaction. 3)如果Job E不稳定,这里我们需要实现用户交互。 In user interaction, user need to change the Job E UNSTABLE status to either success or failure.在用户交互中,用户需要将 Job E UNSTABLE 状态更改为成功或失败。

Eg:- If job E UNSTABLE, in user interaction.例如:- 如果作业 E 不稳定,则在用户交互中。 user click on proceed, job E changes unstable to SUCCESS user click on NO, job E changes unstable to failure.用户单击继续,作业 E 将不稳定更改为成功用户单击否,作业 E 将不稳定更改为失败。

I would not recommand trying to change status of aa build.我不建议尝试更改 aa 构建的状态。 Your use case is perfect for pipelines.您的用例非常适合管道。 Ideally, I would recommand to get rid of the freestyle jobs and develop a proper pipeline.理想情况下,我会建议摆脱自由式工作并开发适当的管道。

If you can not, you can still orchestrate freestyle jobs from groovy pipelines.如果不能,您仍然可以从 groovy 管道中编排自由式作业。

To trigger a job from a pipeline :从管道触发作业:

build job: jobFullname, parameters: listOfParameters

See for more options . 查看更多选项

To display a message waiting for a decision :显示等待决定的消息:

input "Continue or abort pipeline ?"

See for more options . 查看更多选项

If you still want to change build status, you first need to find the job :如果你仍然想改变构建状态,你首先需要找到工作:

Job job = (Job) Jenkins.instance.getItemByFullName(jobFullname)

Then find the run you want to change :然后找到要更改的运行:

Run run = job.getBuildByNumber(buildNumber)

or more conveniently, get the full list and loop in it to find the one you want :或者更方便的是,获取完整列表并在其中循环以找到您想要的列表:

RunList<RunT> runs = job.getBuilds()

Then, once you have the run you are looking for :然后,一旦你有你正在寻找的运行:

run.setResult(Result.SUCCESS)
run.setResult(Result.FAILURE)

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

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