What is CI-CD ?!!

Sana Ebadi
7 min readFeb 28, 2021
what is CI-CD?!

CD (Fastlane) + Android + Slack :

Certainly process automation is one of the concerns of this period! What we want to learn today is to automate the “build” process and deliver the version to “testers” or members of the organization.

The first step is to know what a CD is!

This is an acronym for continuous delivery (or deploy, which of course are different, but we consider the same here), which Wikipedia translates as continuous delivery / deployment, the purpose is, in short, that when we work on coding and unit test And … we did, let’s go and do the steps to deliver the “program” to the testers or upload it to the markets.

The tools we use for Android are fastlane and slack (which, of course, are better alternatives to fastlane, which, as far as I know, have either pollen or other problems, Google itself has offered fastlane as one of the suggested options in its documentation).

The fastlane tool is actually a Ruby platform for Android and IOS that can do the following:

  1. Take a screenshot of the app (for the market)
  2. Get the beta version (test) to the testers
  3. Leave the release version in the markets
  4. Sign your program automatically

We are dealing with number 2 here!

The first step is to get the tools, first we have to download ruby

Now open cmd and type this command (if you have Linux or Mac and do not have root access, leave sudo):

Go to the project path commands (cd your project) and create a fastlane for that project:

And that’s it! Now fastlane is made for your project and its sign is that the fastlane folder should be next to the app folder and … and it should also have two Appfile and Fastfile files, you should write the relevant commands in the fastane file, but before that, let’s go to slack, our goal is to load the build we want into slack this way so we have to do the slack settings first

After we launched slack and had the workplace and so on. We need to get a token from slack with a url that allows us to automate, go to the following site and follow the steps according to the photos:

Slack Config

In step 7 it gives you the webhook url you need for fastlane (I did not put the photo of the part where your webhook is, you can access all the webhooks you created through the incoming webhooks option) and in step 9 it gives you the token Gives that you will need it again!

Well now let’s go to fastlane, fastlane commands have the following format (first line optional):

Now we create a lane to get the copy and upload it, we write the upload part as a separate function (optional):

What these commands do is come through the apps that slack gives us (instead of web hook url, accsess_token, and channel_name, you have to put the phrases you want, the first and second that come from the previous processes, and the third specifically The name of the channel you want to upload the file to) How to build a Successful! Sends it to the desired channel and then loads the version, we can specify after the upload_to_slack function that when the processes are finished, it will leave another message in the slack to indicate whether we got an error or not:

and over ! The output that we finally have is that two messages, one before and one after uploading our apk file, are placed in slack and the apk file is given to those we specified. To run the case, you have to go to the folder via cmd or terminal. Project and write this there:

fastlane android slack_build

CI + Android + GitLab

One of the difficulties in producing a program is the integration and integration of code, surely you have encountered the nightmare of “conflict” many times in your development! We use CI to solve such problems!

This is an acronym for Continuous Integration, which Wikipedia translates as “continuous integration.” If we use the definition of Wikipedia as a criterion, this is:

In software engineering, continuous integration (CI) is the practice of merging all developers’ working copies to a shared mainline several times a day.[1] Grady Booch first proposed the term CI in his 1991 method,[2] although he did not advocate integrating several times a day. Extreme programming (XP) adopted the concept of CI and did advocate integrating more than once per day — perhaps as many as tens of times per day.[3]

As you can see in the figure, after development, we commit our code, and as soon as we commit, we execute a hierarchy of commands (which we call pipeline). In this series of steps, we build the project, the tests that We execute and review the writing and finally go to the CD stage.

What we are doing now in this article is to create a project and run its pipeline, which consists of three steps: build, test, and deploy. To do this, we can use different tools, which is the best GitLab tool for Android.

Step 1 — Build the project

Create a project and create a repository in GitLab and cover it there.

Step 2 — Create a CI-CD configuration

Gate Lab itself provides the complete CI-CD tool for us, select this option (Set up CI/CD) :

With this click, a file in yml format is generated for us, where our configuration is done, so this page should be rotated:

Well, we will write a series of scripts in this file and then show how these scripts are going to be executed in a pipeline, we define a series of stages in this file, these stages are actually our pipeline stages There are three steps in the example we give (we said above), we connect them to a specific function with the commands that yml has .

First of all, the desired image must have Android Studio and fastlane commands:

image: vratislav/gitlab-ci-fastlane-android

Next we need to define the Stages:

- build
- test
- deploy

This part must also be executed before the operation:

before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlew

We have the above three stages, we have to define them one by one, starting from build:

build:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/apk/app-debug.apk

You see, we go to assembleDebug to step number 1, that is, build, and then we enter the command needed to prepare the debug version (actually a console command that you have in the same terminal of Android Studio and nothing special), the next step is To run unit tests:

debugTests:
stage: test
script:
- ./gradlew test

If you pay attention, this is also very simple, in fact, it is the same Android Studio commands that we use in the terminal or cmd or anywhere else, the system is told to run test files, the last step is a little different than in another article I explained and here I am just writing the script:

deploy_internal:
stage: deploy
only:
- master
script:
- fastlane slack_build

The script above is, we have a tool for CD called fastlane, the keyword when specifies when this step should be performed, and the word only says that whenever we perform the commit and push operations from the master, come to this step deploy for Do it, otherwise, if we were from other branches, it would not matter!

And that’s it! Now you have set up the system with three steps and for each commit from the master comes three steps and from other branches comes two more steps, you can see the work routine from this section:

pending
passed

yml file Completely :

Thanks for reading! And if you enjoyed it, gimme a clap

Sana Ebadi |16:15 PM Sunday, 28 February 2021

--

--