Pragmatic programmers automates everything :)

 

Yes! And why not build a script for your Jenkins build. Well, it’s not that hectic but still requires few steps:

·      Open the browser.

·      Write the Jenkins URL.

·      Login.

·      Find the job.

·      Click build. :)

 

Won’t you feel happy, if the same operations work for only one step? Write the command and press enter! Boom!! :)

 

Lets see how to accomplish this. :)

 

We have discussed the solution here based on the OS.

 

OS X

 

If you are a Mac guy/girl, its pretty easy. Just write the following command:

 

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

 

Do not forget to replace the placeholder values.

·      Jenkins User Configure<your_jenkins_username> is your Jenkins username that you use to login to Jenkins.

·      To get your <your_jenkins_API_key>:

o   Login to your Jenkins.

o   Click on the username in the top right.

o   Click on Configure.

o   Jenkins user get API tokenClick on ‘Show API Token’ button.

o   You got it. :)

·      <jenkins_server_url> is your respective Jenkins server URL (development or staging).

·      <your_jenkins_job_name> is the job that you want to build.

 

Prepare the command by replacing the placeholders with proper values as described above and run it.

 

That’s it. :)

Isn’t it fabulous? :)

 

Do not forget to save the command somewhere. You can also create different batch files for different projects for even easier operation. :)

 

Linux

If you are a nix guy/girl but could not catch the Mac yet, don’t worry. :) You can just follow the instructions for OS X above. It will just work. :)

 

Alternatively, you can use 'wget' instead of 'curl' if you’re a wget fan. :) 

And if you're a 'wget' fan, you already know how to use 'wget'. Hence, I am not repeating the instructions for 'wget'. :)

It's just replacing 'curl' with 'wget' and parameter are same. :)

Doesn't work? Better use 'curl' lah... :)

 

Windows

 

That’s the 3rd in my list. If you are actually a *nix guy/girl but somehow forced to use windows and helpless :|, Why don’t you use gitbash in windows and use *nix commands. :) That will just work. :)

 

If you do not understand, what I mean, (then probably you're not a *nix person :P) ‘gitbash’ is a program combined of git and bash. A bash is shell that runs commands once you type the name of command and press enter. :)

 

For *nix fans in windows, good news is, gitbash accepts all basic *nix commands. :)

 

·      Download  the git bash from here https://code.google.com/p/msysgit/downloads/list?q=label:Featured (at the time of this article writing, it was named as Git-1.9.0-preview20140217.exe) and install it.

·      Just follow the instructions from OS X section and you are done :)

 

However, if you are a born windows user and scared of *nix, you can use Jenkins-cli.jar to run command line build commands.

 

·      Download Jenkins-cli.jar from http://<your_jenkins_server_url>/jnlpJars/jenkins-cli.jar. (Here <your_jenkins_server_url> is your respective Jenkins server URL (development or staging))

·      Go to http://<your_jenkins_server_url>/cli and build your command by following the instructions there.

 

Again do not forget to save the command somewhere. You can also create different batch files for different projects for even easier operation. :)

 

Disclaimer: I am using OS X/*nix while writing this article and hence tested those environments. I did not test the windows .jar option. Please let me know if you face any issue here. I will fix/correct and will update this article. Thank you!

And please forgive my pinches for using windows. I just could not love windows over *nix OSes yet.

 

 

Add new comment