Calling a Jenkins build from outside of Jenkins?

后端 未结 10 2068
刺人心
刺人心 2020-11-27 15:49

I am new to Jenkins, and I\'m not sure if this is possible, but I would like to set up a web interface where somebody could click \"Start Job\" and this will tell Jenkins to

相关标签:
10条回答
  • 2020-11-27 16:26

    Install Generic Webhook Trigger plugin. Select generic webhook trigger in build trigger actions. Generate a random string and paste in token. Now your job can be triggered with a http request to the following url.

    screenshot

    http://JENKINS_URL/generic-webhook-trigger/invoke?token=TOKEN_VALUE

    replace your jenkins url and token value

    0 讨论(0)
  • 2020-11-27 16:27
    curl -H POST http://USERNAME:PASSWORD@JENKINS_HOST:PORT/job/JOB_NAME/build?token=YOUR_TOKEN
    

    Set YOUR_TOKEN at job configuration -> build triggers -> Trigger builds remotely.

    0 讨论(0)
  • 2020-11-27 16:28

    Here is a link to the documentation: Jenkins Remote Access API.

    Check out the Submitting jobs section.

    In your job configuration you setup a token and then create a POST request to JENKINS_URL/job/JOBNAME/build?token=TOKEN. That's probably the most basic usage.

    0 讨论(0)
  • 2020-11-27 16:30

    Aha, I found it in the documentation. So simple:

    http://YOURHOST/jenkins/job/PROJECTNAME/build
    
    0 讨论(0)
  • 2020-11-27 16:30

    I needed to add parameters and I wanted to do it over https. It took me a while but the following worked for me:

    curl --request POST --url 'https://HOST_NAME/job/JOB_NAME/buildWithParameters?token=TOKEN'  --header 'cache-control: no-cache' --header 'content-type: application/x-www-form-urlencoded' --data 'name1=value1&name2=value2'
    
    0 讨论(0)
  • 2020-11-27 16:30

    There is a good sample of using the above API from Python. The project is called Python Jenkins, and you may find it here: link

    0 讨论(0)
提交回复
热议问题