How to delete Jenkins jobs using remote access API

This is why proper API documentation and proper status code is important ๐Ÿ˜€๐Ÿ˜€๐Ÿ˜€

Spend half an hour trying to figure out how to delete a #Jenkins #job using โ€œJenkins remote access APIโ€ ๐Ÿ˜ฉ ๐Ÿ˜ค ๐Ÿ˜ฎ ๐Ÿ˜ฑ

You can access all the methods support for an endpoint say for the below job:

https://<Jenkins_url>/job/<job_name>

atย : ๐Ÿ‘‡

https://<Jenkins_url>/job/<job_name>/api

The documentation at this endpoint says, to programmatically delete a job, just do DELETE to โ€œThis URLโ€, which on clicking takes us to: ๐Ÿ˜– ๐Ÿ˜ซ ๐Ÿ˜ฉ๐Ÿ‘‡

https://<Jenkins_url>/job/<job_name>/

so I tried #DELETE method onย : ๐Ÿ˜‘ ๐Ÿ˜’ ๐Ÿ‘‡

https://<Jenkins_url>/job/<job_name>

And guess what we get status #200 but the job never gets deleted after playing around for half an hour by reading many answers online and inspecting the #network tab when you do delete from UI. I identified the below endpoint to do this: ๐Ÿ“Œ ๐Ÿ“ ๐Ÿ“Œ ๐Ÿ“ ๐Ÿšฉ

https://<Jenkins_url>/job/<job_name>/doDelete

But was still wondering why the documentation was wrongย !!! so gave a last try of adding the front slash as per the URL opened up in the browser: ๐Ÿ™๐Ÿ™

DELETE https://<Jenkins_url>/job/<job_name>/

Guess whatย !!!!! ๐Ÿ’ฐ ๐Ÿ’ฐ I got a status code #204 and JOB got deletedย !!!! ๐Ÿ˜‚ ๐Ÿ˜ƒ ๐Ÿ˜„ ๐Ÿ˜…

so note: front slash is important if you are playing with Jenkins remote access API ๐Ÿ˜‚ ๐Ÿ˜ƒ ๐Ÿ˜„ ๐Ÿ˜…

#jenkins #devops #qaengineers #api

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.