CI and CD for lazy people 😯

Here is one fact about me: I just love shell (not a company). Maybe you have a question, why? Or WTF?. The answer is pretty simple: I love the Shell because it is a compact language. For instance, I wrote a bot for telegram in 20minutes and 11 lines of code. And I made the article about it.

I’ve also started using Shell for CI system too. So, I have following reason for creating CI in my project:
1. Six apps in Google Play;
2. Two project libs.

Project teams :

We have the project team, with such roles:
1. QA team;
2. PM (Project manager);
3. Developer teams.

QA

What do the guys from QA team need?
1. What did developers do in each build? (in case with testing features in the build)
2. What did developers in the sprint? (when it come to regression before publishing an app to alpha channel)

PM

PM need information about what each member is currently doing.

Developers

Developers team consists of :
1. Two mobile teams, Android and IOS;
2. Two team who makes Web part of the project, user and admin websites;
3. Backend team.

So that sums up the basic project overview, now lest’s have a peek at the delivery criteria of our CI system:
1. Auto update fixVersion on Jira tickets.
2. Make the list which developers implement in each build and each sprint.
3. Integration of slack, with immediate notification.

CI system for each team would be a plus.

Why have I chouse Shell script to solve to the problem. Why? Because Shell, can be executed in each CI system, For example, Jenkins (As simple CI system). Well, this is who it works: shell script gets all commit messages between last success commit and current commit (Git name: HEAD). Get all Jira ticket keys form them, make a new version of the project into Jira, update fixVersion field in each ticket from commits, send a message to Slack with release notes.

How to put ticket key into the commit message
First way:

git commit -am []




Secord way:

If you use JetBrains Idea (Android Studio, in my case), you should make integration with Jira, and Idea will automatically add ticket key into commit message.

Configure Jira in JetBrains Idea

Register Slack bot

Create new slack bot

Go to slack.api for registering new bot for slack.

Click Start Building

Type App name, and selected your slack workspace.

By default, your Slack bot doesn’t have any permissions.

Go to your bot page and selected OAuth & Permissions, scroll to Scopes, and add “Post to specific channels in Slack” permission for your bot.

Add permission

Without this permission bot cannot send any message to your Slack channel. Go to Incoming Webhooks. In the bottom part of the screen, you can see Webhook URL, copy it we will use on next step.

Setup environment

We will need following environment values:

PROJECT_KEY=
SLACK_HOOK=
JIRA_URL=
Init environment values on Jenknis

Make an array of tickets key

KEYS=$(git shortlog -n ${GIT_PREVIOUS_SUCCESSFUL_COMMIT}..HEAD — oneline | cut -d ']' -f1 | cut -d '[' -f2 | grep "^IM")

GIT_PREVIOUS_SUCCESSFULL_COMMIT — SHA of the previous successfully built commit from the same branch.

shortlog— works in the same way as a log, but commits grouping by the author, and show only first line from the commit message.

-n — sorting that group by alphabet.

cut -d ']' -f1 | cut -d '[' -f2 — get from string substring between brackets.

grep "^[PROJEC_KEY] — remove all strings which don’t start to form the key of your project on JIRA.

Save command result into releaseNote.txt file.

Update Jira tickets

Setup environment for jira integration.

Add Jira username and password to Jenkins

Also, you can add username and password in the way I’ve mentioned earlier in this article. I will use curl to execute REST calls to Jira API.

Create new version for project on Jira

BUILD_NUMBER — The current build number, such as “153” (From jenkins default envirnment).

Update fixVersion for tickets on Jira

Each time when your CI execute such shell scripts, they update fixVersion field on Jira tickets.

Slack integration

It is out of the question the Jira can send you E-mail with all the updates. But I found more useful way to send notification about new build to the team. Shell script witch sends a simple message to project slack channel.

Simple message

More information message

Slack message from my project

In my case, I added links to all tickets, which made in the build. That script creates links to each card by ticket key and collects in one string and then CI system sends the message to Slack.


Summary

We created a workflow for our project, using the shell scripts. CI update fixVersion in Jira cards, and send message about new build to Slack channel. We can use it for each part of the project because that system does not any change in the project source code.

You can find all the codes I mentioned before on my GitHub, project.

The article publish on my medium

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s