2

How do I trigger builds remotely?

I followed some tutorial and ready with this below:

Curl user `sanveen:585da82e7d3df2991dea3533ea794d06 `

The M link format is http://localhost:8080/jenkins/job/triggerbuild/build?token=gitbitsolution6789

The authentication token set in the jenkins-plugins section.

But where do I call this and trigger the build?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Sanveen
  • 109
  • 1
  • 5
  • 9
  • Lets suppose you have two machines A and B. On machine A jenkins is configured. And your purpose is to trigger builds from machine B. In order to do that you configure jenkins to allow builds using scripts. and make an http request to machine A from machine B. – Talha Junaid Jan 07 '18 at 06:37
  • Is there way to save this settings in. Sh file and trigger the build once committed? I want to trigger the build now..please provide me the steps to do it – Sanveen Jan 07 '18 at 06:52
  • Yes. Surely you can put that command in .sh file and run that. You can do that from terminal as well – Talha Junaid Jan 07 '18 at 06:56
  • Thank you Talha. I opened git bash and created hooks.sh by vi editor.Added these comment Curl user sanveen:585da82e7d3df2991dea3533ea794d06 http://localhost:8080/jenkins/job/triggerbuild/build?token=gitbitsolution6789 and run the script file. Before running the script, i set the anonymous user access in jenkin security. Jenkin build triggered successfully. However i got this message "Could not resolve host: user" after run the script file – Sanveen Jan 07 '18 at 07:50
  • You should always have security in place to avoid from attacks. For this issue you can post another question. – Talha Junaid Jan 07 '18 at 07:54
  • See also *[Trigger build via URL gives me no crumb included in request error](https://stackoverflow.com/questions/40884446/trigger-build-via-url-gives-me-no-crumb-included-in-request-error/45396361#45396361)*. – Peter Mortensen Jul 18 '18 at 14:32

1 Answers1

1

Let's suppose you have two machines A and B. On machine A Jenkins is configured. And your purpose is to trigger builds from machine B. In order to do that you configure Jenkins to allow builds using scripts. And make HTTP POST requests to machine A from machine B.

To send POST requests to machine B, you can make use of curl and create a Bash script to trigger a build.

For example,

curl -X POST http://API_TOKEN_USER_ID:API_TOKEN@your-jenkins.com/job/JobName/build?token=AUTHENTICATION_TOKEN
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Talha Junaid
  • 2,351
  • 20
  • 29