https://miro.medium.com/max/1400/1*UygqduG_G1DmPOmpHGxbSA.png

How to trigger Jenkins Job with Bash Script?

Birol EMEKLİ
2 min readMay 16, 2022

--

Hello everyone after a long time :)

I haven’t been able to write an article for a long time because I’m very busy. I thought and said to myself that I should write something. So Now, I decided to write small acticle. :)

How to trigger Jenkins Job with Bash Script?

I think everyone know the Jenkins. We have been used it in CI/CD processes for a long time. But how to use for it with bash script? Now, we are going to learn it.

Jenkins has API support. We are going to make to requests with curl after we will have csrftoken. Now, we can taking to step by step.

First step, We will API token generate for user then we will use it for connect session. Now, Login to Jenkins and go to your profile page. Then click the configure on button. You will see the same as the picture below. You should generate token from API token section and you don’t forget token (copy) because we will use the token in bash script.

https://miro.medium.com/max/1400/1*MyOPU9Tibuix3J67m2p-9w.png

Second step, we can start writing bash script. You can write script code as below. You have to complete in the special fields there then you should run code. You can send the parameters in the job with -F. You can also see line 20.

If it’s success then you will see trigger job on Jenkins but If you see “CRUMB ERROR” then you check in script. You must make sure all custom fields correct.

See you in an another article :)

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Birol EMEKLİ
Birol EMEKLİ

Written by Birol EMEKLİ

Systems Administrators | DevOps | ML & DP | Python | Django

Responses (1)

Write a response