LOGIN
Sign In or Register
Avatar
Not Registered Yet?

Join Now! It's FREE. Get full access and benefit from this site

Reset My password - Remind Me My username

Username
Password
Remember me

Jenkins Command line Reference for login and trigger a job

Grep will return 0 while the build is running:

$ curl http://myjenkins/job/myjob/lastBuild/api/json | grep --color result\":null

 

$ echo $?

 

Trigger a Jenkins Job from command line

 

$ wget http://yourserver/job/MyJobname/build?delay=0sec

$ wget -O - $HUDSON_URL/job/JOBNAME/build

 

Trigger a Jenkins Job without authentication

$ curl http://jenkins:8080/job/my%20job/build

 

Trigger a Jenkins Job with authentication

$ curl --user dbacher:$MY_API_TOKEN http://jenkins:8080/job/my%20job/build

$ curl --user <your_jenkins_username>:<your_jenkins_API_key> http://<jenkins_server_url>/job/<your_jenkins_job_name>/build

 

Running commands against a secure Jenkins (basic auth or ssh keys)

$ java -jar jenkins-cli.jar -s http://myjenkins help --username me --password mypassword

$ java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa

 

Triggering a job build against a secure Jenkins (avoiding a 1.5 year old open bug!)

$ java -jar jenkins-cli.jar -s http://myjenkins build 'My Awesome Jenkins Job' -i ~/.ssh/id_rsa

$ java -jar jenkins-cli.jar -s http://myjenkins build 'My Awesome Jenkins Job' -i ~/.ssh/id_rsa -s -v

 

Passing parameters when triggering a job build

$ java -jar jenkins-cli.jar -s http://myjenkins build 'Deploy XYZ App' -i ~/.ssh/id_rsa -s -v -p target_env=api.cloudfoundry.com -p branch=master

 

Reference

http://starkandwayne.com/articles/2013/04/12/jenkins-builds-from-cli/

http://www.scmgalaxy.com/index.php?option=com_k2&view=item&id=890:ways-to-login-jenkins-using-command-line&Itemid=120

 

Appendix

1. How to get your_jenkins_API_key?

  • Login to your Jenkins.
  • Click on the username in the top right.
  • Click on Configure.
  • Click on ‘Show API Token’ button.
  • You got it.
Rate this item
(1 Vote)
Rajesh Kumar

.

Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.