简体   繁体   中英

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). Job E is the report generation job, here we need to implement user interaction for Pipeline will continue or not?.

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. 3) if Job E is Unstable, here we need to implement user interaction. In user interaction, user need to change the Job E UNSTABLE status to either success or failure.

Eg:- If job E UNSTABLE, in user interaction. user click on proceed, job E changes unstable to SUCCESS user click on NO, job E changes unstable to failure.

I would not recommand trying to change status of aa build. 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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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