08 February 2014

How to trigger a Jenkins build on git commit

I spent quite some time figuring this out, but was happy when it worked. This is for Windows. In Linux, the process is the same, but it's far easier.

First, you have to know that if you've installed Git in Windows, it comes with curl pre-installed. So just open the Git bash prompt and start typing your commands.


Let's say you have a Jenkins job setup on localhost, named "someJob". To initiate a build, just type the following command in the Git Bash prompt:

curl http://localhost:8080/job/someJob/build?delay=0sec

That's it. Once you've typed the command, just have a look at your Jenkins dashboard and you'll see your project building. (you might also want to know about this)

Now to make a Git commit trigger the build, you have to navigate to the hidden ".git" directory in your git repository. Enter the "hooks" directory and you'll see there, a "post-commit.sample" file. You can open it with Notepad++ to see the contents of it.

Make a copy of the file and name it "post-commit". It does not need an extension. This is the file that Git will invoke whenever you do a commit to this particular Git repository. Don't worry about the fact that it looks like a Linux bash script. When Git triggers it, it will run even in Windows. If the file has a line ": Nothing", you can remove that line and insert this new line:

curl http://localhost:8080/job/someJob/build?delay=0sec

Now save the file, make some changes to your git repository and commit the changes. The moment you commit, you'll see the build being triggered in Jenkins! Awesome! :)


-----------------------------------------------------------------

Additional note: Many people reach this page via a StackOverflow answer. One such person (see comment below answer) mentioned being confused about what "someJob" was and also had faced an issue with his project name having a space in between, so he had to substitute "%20" in place of a space "codecept%20tests". Hope his response would be of help to anyone else who faces a similar situation. Thank you Paul.


07 February 2014

Access GitHub with an authentication token instead of your Github password

I'm currently using the SmartGit client, as it's good and crossplatform. When I wanted to connect to my GitHub repository for a hobby project I was working on, I was a bit uncomfortable sharing my Github password with the application. Good thing is, Github allows you to also create a token which SmartGit can use to authenticate.

Click on settings on the top of the page:
Select "Applications" and "Create a new token". Use the hash value that gets generated (and treat this token like you would treat a password)


05 February 2014

Contributing to the open source community

How many developers actually help out in the open source community? The numerous software we get to use for free are a result of people willingly putting in effort to create good quality software. I believe that if we are using such software, we can also help the community by contributing back.

Some ways you can contribute:

1. Be a part of the forums / mailing-lists and answer queries of people struggling with learning / implementing the software. I've been a member of some forums and mailing lists under various usernames (Actionscript, Intel TBB, Processing, OSG, OGRE, Stackoverflow and it's sister sites, linuxforums, ffmpeg, netsnmp, SDL and many others).
2. Join the development of the software and contribute patches. Websites like OpenHatch can help you get up to speed with the process.
3. Allow the software to report back crashes and anonymous usage statistics. The latter helps the dev's to improve the UI and interactivity by having authentic user journeys. I've allowed these for Fedora, Netbeans and a few other software.
4. When you find a bug, report it on their issue tracking system. I filed an issue today.
5. Sponsor them. Jenkins allows you to sponsor a particular issue. Other projects allow you to donate to the overall development effort. These people really do deserve sponsorship for the great work they're doing.
6. Add to the Wiki. Most projects have a Wiki page which you can add useful information to.
7. Create tutorials. Many users have a tough time learning how to use a software. You can create video tutorials and post them on youtube or post tutorials on your blog. I used to create tutorials on Stackoverflow too: my Mutex tutorial becoming the highest ranked in Google searches.

Doing all this not just makes you a good contributor to the community, it also expands your skills. It makes you a better developer, as you get exposure to international best-practices, standards, technologies. It improves your communication and hones your technical skills. I'd encourage every software developer to participate. All the best!

Say thank you or donate

04 February 2014

How to install plugins for Jenkins?

I wanted to install the plugin for Gradle and was perplexed that there was no download button on this page: https://wiki.jenkins-ci.org/display/JENKINS/Gradle+Plugin

A bit more searching led me to: https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Howtoinstallplugins

Start Jenkins on your browser, go to "Manage Jenkins" and you'll see the option for "Plugin manager".

Select which plugins you want, and install them. It'll take a while for it to download and install. As the how-to page says, you can also install the plugins manually.

I chose the following, as there was quite a bit of experimentation I wanted to do with a lot of tools. A pity there wasn't any ready plugin for graph databases:

  • Git Client Plugin
  • SCM API Plugin   
  • Git Plugin   
  • Git Server Plugin   
  • Git userContent plugin   
  • Git Chooser Alternative Plugin   
  • ruby-runtime   
  • git-notes Plugin   
  • Static Code Analysis Plug-ins   
  • Task Scanner Plugin   
  • Database Plugin   
  • PostgreSQL Database Plugin   
  • LDAP Email Plugin   
  • MSBuild Plugin   
  • Cobertura Plugin   
  • EasyAnt Plugin   
  • GitBucket Plugin   
  • SSH Agent Plugin   
  • The Continuous Integration Game plugin   
  • jQuery Plugin   
  • jQuery UI Plugin   
  • Terminal Plugin   
  • ClearCase Plugin   
  • ClearCase Release Plugin   
  • Gitlab Merge Request Builder Plugin   
  • Gitlab Hook Plugin   
  • JUnit Attachments Plugin   
  • xUnit Plugin   
  • JSUnit plugin   
  • GitHub API Plugin   
  • AnsiColor Plugin   
  • JSGames Plugin   
  • Mercurial Plugin   
  • Git Parameter Plugin   
  • Github OAuth Plugin   
  • Build Monitor Plugin   
  • CodeCover Plugin   
  • NUnit Plugin   
  • ClearCase UCM Plugin   
  • jQuery UI Plugin   
  • Valgrind Plugin   
  • MySQL Database Plugin   
  • Eclipse Update Site Plugin   
  • jQuery Plugin   
  • Parameterized Trigger Plugin   
  • Build Pipeline Plugin   
  • HTML5 Notifier Plugin   
  • Gitorious Plugin   
  • Git Plugin   
  • Trac Plugin   
  • ClearCase UCM Baseline Plugin   
  • Python Plugin   
  • Checkstyle Plugin   
  • Gradle Plugin   
  • JDK Parameter Plugin   
  • cmakebuilder Plugin   
  • ClearCase Plugin   
  • Active Directory plugin   
  • Signal killer   
  • MySQL Authentication Plugin   
  • Metadata plugin   
  • Git Client Plugin   
  • Git Server Plugin 
  •  Parallel Test Executor Plugin

Did you notice that there's a The Continuous Integration Game plugin? I felt it was pretty cool of them to have brought in Gamification into CI.

03 February 2014

Getting Gradle integrated into Eclipse

It was nice learning Gradle, but I felt it'd be a bit more convenient to have Gradle inside the Eclipse IDE. Gradle is already present in the Netbeans IDE, but for Eclipse you have to install it like so:

This project at Github is what you need: https://github.com/spring-projects/eclipse-integration-gradle

From the documentation on the website, just follow the same steps:
  • Open the Eclipse IDE
  • Select Help > Install new software
  • Paste a Gradle update site link (http://dist.springsource.com/release/TOOLS/gradle) into the "Work with" text box. 
  • Ensure that the option "Group Items by Category" is enabled.
  • Select the top-level node 'Extensions / Gradle Integration'.
  • Click "Next".
  • Review the list of software that will be installed. Click "Next" again.
  • Review and accept licence agreements and Click "Finish".
It'll take a while to install:


Now in Project Explorer, right click on your project, go to Run As > 2. Gradle... to run the project under whichever tasks you want to select.


You don't always have to return to this dialog box. The next time, you can simply run the selected tasks using Run As > 1. Gradle.
If you add any tasks externally, click the refresh button to view that task.

It's that simple. Happy building! :)

01 February 2014

How to add the path of the JDK to JAVA_HOME in Linux?


If you've already installed the JDK, it's as simple as this:
type locate jdk and search for the path.

Mine was in /usr/local/jdk1.7.0_45/

So I opened up bash_profile with
vim ~/.bash_profile

and added the following line into it.
JAVA_HOME=/usr/local/jdk1.7.0_45
export JAVA_HOME


Also add :
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/gradle-1.10/bin:/usr/local/jdk1.7.0_45/bin
 

So that when you execute commands like jar -xf somejar.jar, the executables will be recognized.


Then type source ~/.bash_profile to activate the changes you made (basically the whole of bash_profile will be executed again).

That's it! all programs will recognize JAVA_HOME. I had to do this for Gradle to recognize the path. Without the path, it didn't compile Java programs.