Ruby gem to fetch information from gocd as rich models

What is GoCD?

GoCD is a product built by ThoughtWorks to Automate and streamline your build-test-release cycle for reliable, continuous delivery of your product. You can read more about it here.

Why this Gem?

GoCD server provides some nice apis using which you can get the information about your builds, pipelines, agents etc. from your GoCD server. It provides that information in json/xml format. Now to utilize that information you will carve models out of that json/xml or just use it as hash map which is not very neat. Also you will have to write so much extra code to make a call and parse the json/xml to get to a specific peace of information.

So, here is gocd ruby gem to rescue.


To install gocd gem just add below line to your Gemfile.

You can also install it directly and try out in irb.


What does gocd gem do?

gocd ruby gem helps you to get the information from GoCD server in a neat and clean fashion. Lets take an example and see how this gocd gem can help us.

Problem statement: I have a repository in github called MyRepo. Whenever someone pushes code in this repo, GoCD server runs 3 different pipelines to test the integration of old and new code. Now if any of those pipelines are red/failing, I don’t want anybody to push their code.

Cool, now we have a problem in hand. Lets see how we can solve it.

Lets solve it step by step:

  1. Make a call to GoCD api to get the information of pipelines.
  2. Filter out the group of pipelines that you are interested in.
  3. Check the status of those pipelines
  4. If any of the pipelines are red do not allow to push.

Now that we have our dev tasks defined, lets see how we can complete theses tasks with the help of gocd gem.

Now run this script as part of your pre-push git hook and you are done. Neat and Clean!!

What else it can do?

Currently gocd gem can provide you information about:

  1. All pipelines and their statuses
  2. Information about a group of pipelines
  3. Information about go agents

Below is how you can use these features:

Its Open Source…

gocd gem is open source. If you want this gem to provide you some other information which is not there yet, please comment below and I will try implementing it ASAP. Or you can also contribute to this gem.

Leave a Reply

Your email address will not be published. Required fields are marked *