Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Jenkins build using batch script

I am working with a Jenkins build server to run synthesis/simulation for FPGAs. Right now I have nightly builds and can start the build manually in Jenkins browser interface.

My question is:

Is there any possibility to start a job build with a batch script without using browser interface?

(I am running Jenkins on Windows 7 64bit.)

like image 873
michi.b Avatar asked Apr 11 '16 12:04

michi.b


People also ask

How do I run a Jenkins batch script?

Add the batch command as run. Click on Apply and save the configuration then, you will redirect to the Project Workspace. Click on the Build Now, it will execute the given batch command that executes the run. bat file. You can see the console results on the Console Output.

How do you trigger a build in Jenkins?

Create a remote Jenkins build trigger in three stepsCreate a Jenkins build job and enable the Trigger builds remotely checkbox. Provide an authentication token; This can be any text string of your choice. Invoke the Jenkins build URL to remotely trigger the build job.

Which command runs Jenkins from the command line?

Run the command java -jar jenkins. war . Browse to http://localhost:8080 and wait until the Unlock Jenkins page appears.


1 Answers

In the new Jenkins Pipeline, under Build Triggers, select the checkbox Trigger builds remotely (e.g., from scripts). Then give Jenkins a token that will be required when triggering the build.

Not authorized errors

A problem with triggering the builds remotely is, if you've set up Jenkins right and disabled anonymous user access, you will get Not authorized errors when you try to trigger the build from a script (as @keocra pointed out). You now have two options:

  1. Pass a username and password along when you trigger the build. This means that your script will need to include the username and password, which means everyone who can read your script will have the username and password, which is almost as bad as anonymous access.
  2. Use the Build Token Root Plugin. This plugin allows you to use the Trigger builds remotely feature without requiring the username and password. All you need is the token you generated before.

Triggering the build

To trigger the build remotely, run

curl JENKINS_URL/buildByToken/build?job=JobFoo&token=MyToken

Where JENKINS_URL is the URL to your Jenkins instance, JobFoo is the name of your job, and MyToken is the token you entered under Trigger bulids remotely.

Of course, you don't need to use curl; you can also use wget or any other program that can make HTTP requests.

like image 181
jpyams Avatar answered Sep 27 '22 22:09

jpyams