How to run any Jenkins Job from the Command Line

This is image title

The last 2 years I have been working with a lot of Jenkins environments and of course, I had to run a bunch of Jenkins jobs every day. And yes, you are right, for each job, you gotta go to a particular Jenkins Web interface, find a particular job and finally, pardon me, run this crappy Job. In short, it made me waste a lot of time on useless things.

Based on this, I decided to make life easier and develop a tool that will help me get rid of these meaningless jobs.

Either this is familiar to you, or if you just would like to simplify your work, then let me take you through a guide on how to get started.

Jenkins-job-cli

This is an open-source CLI tool written in GO to run any Jenkins Job/Build from the Command-line/Terminal: https://github.com/gocruncher/jenkins-job-cli.

Alt Text

Installation

Fetch the latest release for your platform:

Linux

sudo wget https://github.com/gocruncher/jenkins-job-cli/releases/download/v1.1.0/jenkins-job-cli-1.1.0-linux-amd64 -O /usr/local/bin/jj
sudo chmod +x /usr/local/bin/jj

OS X brew

brew tap gocruncher/tap
brew install jj

OS X bash

sudo curl -Lo /usr/local/bin/jj https://github.com/gocruncher/jenkins-job-cli/releases/download/v1.1.0/jenkins-job-cli-1.1.0-darwin-amd64
sudo chmod +x /usr/local/bin/jj

Configure Access to Multiple Jenkins

jj set dev_jenkins --url "https://myjenkins.com" --login admin --token 11aa0926784999dab5  

where the token is available in your personal configuration page of the Jenkins. Go to the Jenkins Web Interface and click your name on the top right corner on every page, then click “Configure” to see your API token.

In case, when Jenkins is available without authorization:

jj set dev_jenkins --url "https://myjenkins.com"  

or just run the following command in dialog execution mode:

jj set dev_jenkins

Shell autocompletion

As a recommendation, you can enable shell autocompletion for convenient work. To do this, run following:

# for zsh completion:
echo 'source <(jj completion zsh)' >>~/.zshrc

# for bash completion:
echo 'source <(jj completion bash)' >>~/.bashrc

if this does not work for some reason, try following command that might help you to figure out what is wrong:

jj completion check

Examples

# Configure Access to the Jenkins
jj set dev-jenkins

# Start 'app-build' job in the current Jenkins
jj run app-build

# Start 'web-build' job in Jenkins named prod
jj run -n prod web-build

# makes a specific Jenkins name by default
jj use PROD  

So, I hope you find this tool helpful. I would be very glad if you haven’t already, please check it out and let me know what you think or what problems you are facing.

So, I hope you find this tool helpful. I would be pretty happy, if you haven’t already, please check it out and let me know what you think or what problems did you face.

##jenkins ##job ##bash ##command-line

How to run any Jenkins Job from the Command Line
1.40 GEEK