My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Wednesday, December 23, 2020

Trigger Jenkins Job Remotely

In some cases, You want to trigger Jenkins Job Build from CLI or programmatic way rather than usual GUI operation where you have to login on Jenkins Web Interface and click on Build button. There might be few reasons to do so such as - 

  • Want to trigger jenkins build from shell/batch script

  • Want to share trigger command/url to user rather than giving access on all jenkins job on server

There can be n different reasons but solution is same which we are going to discuss here. 

  1. Enable Jenkins API Calls -
    • For enabling the Jenkins for API calls, follow the below steps.
    • Go to - http://jenkins_server/user/user_name/configure  (Change the jenkins_server and user_name as per your system)
    • Click on "Add New Token" 
    • Give some name to token and click on "generate"
    • Once token generated, it will be only displayed once, so copy it and save it somewhere secure. 

  2. Test Jenkins API Calls - 
    • Create a dummy test job, in my case, it is job name is "test2"
    • To Trigger this job remotely, Run below commands in terminal - 
    • curl -X POST http://localhost:8080/job/test2/build \
      --user atul:1179517c4b16ab133edd0dd37132007089
      
    • If job is expecting parameters (job - test2_withParams, and parameter are FNAME and LNAME), you can provide them as below -  
    • curl -X POST http://localhost:8080/job/test2_withParams/buildWithParameters \
      --user atul:1179517c4b16ab133edd0dd37132007089 \ -d "FNAME=ATUL" \ -d "LNAME=SINGH"


    So that's it for today, will see you soon.. Till then.. Happy Learning !!


    Like the below page to get the update  
    Facebook Page      Facebook Group      Twitter Feed      Telegram Group     


    No comments:

    Post a Comment

    Disclaimer

    The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
    The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.