Automate everything you can in your development process

Rafaela Guerra
AndroidPub
Published in
4 min readOct 11, 2016

Everyday we try consciously or unconsciously make our life easier to have more time to do things that we like but why we don’t do the same with development process? Or if we do, why we don’t apply this “lazy style” for everything?

Let’s suppose that this is your developing day:

  • You develop some code and tests
  • You run the tests
  • You run some code analyser to detect locking and threading issues, performance, scalability, etc…
  • You open a merge request about your changes
  • You assign someone to review these changes
  • You change the ticket for the review status on your project tracking tool
  • You…

How many times do you repeat this or other process during the week? For sure you have one or more process that you repeat everyday more than one time. Regarding this let’s create a simple rule: Everything that you need to do more than 2 times, please AUTOMATIZE !

“I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.” (by Bill Gates)

How can I make my developing day easier?

This automation process is directly connect with Continuos Integration.

Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily — leading to multiple integrations per day. (…) Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly (by Martin Fowler)

Let’s consider that you are using these technologies in your development process:

  • Version Control Software: Git
  • Code Review : GitLab
  • Project Tracking Tool: Jira
  • Code Analyser: SonarQube
  • Chat for the team: Slack

In my point of view an Automation Server (Jenkins) and WebHooks are the “keys” to start the automation process.

WebHook

You can use WebHook in several tools like Jira, Slack, Gitlab, etc and with it you can notify Jenkins or other web application when certain events occur. In sum WebHook is your event trigger and that will notify other tools about something has changed.

How to connect everything?

With these development tools and these two powerful keys, let’s start to “connect” push events with your Jenkins Server.

And you simply configure this in GitLab going to Settings > Webhooks and point the WebHook to the job that you want to run in your Jenkins Server. In this case the job “job_to assign_developer_to_merge_request” contains a script that will assign the Merge Request for a specific developer.

And now? Let’s notify the developer who was assigned the Merge Request. For this you can use the Slack Plugin in your Jenkins jobs.

As other tools, Slack uses Incoming Weebhooks that allows you to post custom messages from external sources (like messages where you identify people/channels, put custom buttons, etc).

Meanwhile, we can change the status of the ticket regarding code changes in your project tracking tool, for example “to Review”(that in this case is Jira). In my case, I’m using a script to do this, but one more time…there are multiple ways to do the same. First let’s check the transitions available for the specific ticket.

GET /rest/api/2/issue/{issueIdOrKey}/transitions 

For our case we need the transition_id = 131 that is responsible for the move the ticket for “To Review” status. For this we make the

POST /rest/api/2/issue/{issueIdOrKey}/transitions?expand=transitions.fields 

with transition data

‘{“transition”:{“id”: “131”}}’

Have a quick look in the python script that makes this logic, and it can be simply called by the Jenkins Server.

Jira has the WebHook option as well. Please have a look here.

You can also use SonarQube Plugin for Jenkins to run code analyse.

And after several simple steps, we have this:

Conclusion

  • You develop some code and tests
  • Jenkins trigger the tests
  • Jenkins trigger SonarQube to run some code analyser to detects locking and threading issues, performance, scalability, etc…
  • You open a merge request about your changes
  • Jenkins run a script to assign someone to review these changes and Slack notifies the team of the assignment.
  • Jenkins trigger Jira to change the ticket for the review status on your project tracking tool

And about “You”?
Well, now you have more time to do other things …

--

--