Run Jenkins Build From Command Line
Run Jenkins build from command is very simple in Linux system. Jenkins has support to command line client that allows you to access Jenkins from command line.
To Trigger Jenkins build from command line some prequiste are there
- Jenkins service is running.
- Enable security option under “Configure Global Security”
Go to jenkins dashboard in Home page ( e.g http://localhost:8080/ ) -> Manage Jenkins
-> Configure Global Security -> Click on “Enable security” checkbox
You can also configure “Access Control” and “Authorization” option in Global Security page.
Jenkins allow us to trigger Jenkins build with any specific user, For that we have to pass username and password in command line.
You can check all CLI option in http://<jenkins server >/cli/ ( e.g http://localhost:8080/cli/ ) page.
To access CLI feature in Jenkins download jenkins-cli.jar (http://<jenkins server>/jnlpJars/jenkins-cli.jar) and place this jar your directory or location from you are going to run jenkins build command.
Jenkins Command build Option:-
Syntax :-
java -jar jenkins-cli.jar -s http://<jenkins server>/ build build-name [-c] [-f] [-p] [-r N] [-s] [-v] [-w]
Option Descriptions:-
build-name : Name of the job to build
-c : Check for SCM changes before starting the build, and if there's no change, exit without doing a build
-f : Follow the build progress. Like -s only interrupts are not passed through to the build.
-p : Specify the build parameters in the key=value format.
-s : Wait until the completion/abortion of the command. Interrupts are passed through to the build.
-v : Prints out the console output of the build. Use with -s
-w : Wait until the start of the command
e.g.
java -jar jenkins-cli.jar -s http://localhost:8080/ build 'my-project-build' --username roop --password roop
Roopendra,
do you know how to get the source of this command in groovy? In other words, I want to be able to enter Jenkins groovysh and run my build from there. If I just type ‘build build_name’ in groovysh, it burps.
Is there anyway to run multiple jobs in one command.
Jenkins CLI Example