CICD Pipeline using Jenkins

Abhishek Pathak
7 min readOct 1, 2022

--

In this article you are going to lean Jenkins, Pipeline associated with Jenkins process, Developer involvement in CICD and each steps in detail for Merge Request to main branch by feature branch.

Let’s start the learning from basic terms like what do Jenkins do?

Jenkins is an automated server that involves multiple tools and make then integrated with each other to process the Continuous Integration and Continuous Delivery environment.

well, you just got to know about Jenkins but how does a developer involved and multiple processes to get merge your work into main branch is still yet to learn. As a Developer we should follow below steps to make your task done. So let’s begin to know each steps in sequence in detail.

Steps to integrate the Jenkins with multiple pipeline stages

Step 1: Create a branch with Assigned JIRA ticket on Gitlab/Github.

In this step, you have to create a branch and start work on the feature that is mentioned in the description of JIRA ticket. Once you finished your implementation of your task, go for commit and push steps. But after pushing your code is not yet merged to main source branch. So for this merging process, you need to follow multiple steps to ensure that your code is appropriate, best quality code as per the company standard requirement.
For basics of GitHub, you can refer this article.

Step 2 : Raise a Merge Request on Github/Gitlab

Write proper description of your work for clear vision to peer reviewers for your codebase. Once you raise Merge request/Pull request, it will go for multiple pipeline steps.

Step 3: JIRA ticket Verification

This step is validating your branch and make sure that your branch is create under the JIRA assigned ticket. This step also ensure that your JIRA ticket is assigned to you, also verifies the state of JIRA ticket is in progress or not.

Step 4: Maven will verify the test cases and build of Project

This step will run all the test cases written in your codebase and check if it is passing or failing, If all the test cases got passed then it will move to check the whole app is building or not. If everything goes well pipeline will move to next step else failed here and give you a proper report to verify.

Step 5: SonarCube will check the test coverage, and code Quality

SonarCube is an tool that help to check the code quality like duplicity in codebase or security issues in codebase or also check the code coverage written by the developer in the branch is passing the gate quality like 80% or may be more that is general requirement of test coverage.

Step 6: Packaging of all the code into a wrapper and test the build with existing build

This is last step of pipeline to make sure that code is working fine with existing main branch and make it into a package.

Step 7: Peer review process by team developers

This step involve the team developer to check the coding style is up to the mark or not, Kt-lint check, Code formatting is followed or not, then verify the business logic and code logic is up to the mark or not.

Step 8: Approvals by Team reviewers
Once team developer will do a peer review and code looks good to merge into main branch, they can option to approve or reject.

Step 9: Merge the codebase to Master/Main branch
Once you got few required approvals on the opened Merge request, you will got option to rebase/merge into master/main branch and then your responsibility of the assigned JIRA ticket got finished so now you can make the status of ticket to Done.

These all above steps is an integrated steps of Software development lifecycle and CICD process.

Setting up GitHub Actions for an Android repository

It involves creating a workflow file that defines the steps and actions to be executed when specific events occur, such as pushing code to the repository or creating a pull request.

Step 1: Create a Workflow File

  • In your Android repository, navigate to the .github/workflows/ directory.
  • Create a new file with a .yml extension, such as android.yml. This file will define your workflow.

Step 2: Define the Workflow

Here’s an example of a basic workflow for an Android repository:

name: Android CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'

- name: Set up Android SDK
uses: actions/setup-android@v2
with:
sdk-version: '31'

- name: Build with Gradle
run: ./gradlew build

Step 3: Configure Workflow Triggers
In this example, the workflow is triggered on pushes and pull requests targeting the main branch. You can modify the on section to match your requirements.

Step 4: Set up the Environment
This workflow sets up the JDK and Android SDK. It uses the actions/setup-java and actions/setup-android actions to install the required dependencies. You can customize the versions as needed.

Step 5: Build with Gradle
The final step in this example builds the project using Gradle. You can add additional steps for testing, code analysis, or any other tasks your project requires.

Step 6: Commit and Push
Save the workflow file and commit it to your repository. Push the changes to trigger the workflow.

Step 7: Monitor Workflow Execution
Once the workflow is triggered, you can monitor its progress by navigating to the “Actions” tab in your GitHub repository. You’ll be able to see the status of each step and any associated logs.

That’s it! You’ve set up GitHub Actions for your Android repository. Feel free to customize the workflow file to match your specific project requirements, such as running unit tests, generating APKs, or deploying the app.

Checkout the github repository for closer overview

Bonus

Android folks here are some more interview based question from my experience

— — — — — — — — — — — — ||questions|| — — — — — -— — — — — —

What is Continuous Integration, and why is it important in Android development?

Continuous Integration (CI) is crucial in Android development for seamlessly merging code changes. It ensures early detection of integration issues, maintains code health, and accelerates development cycles.

Can you explain the role of automated testing in the CI/CD pipeline for Android applications?

Automated testing in the CI/CD pipeline for Android apps fosters a culture of quality assurance. It includes unit tests for isolated components, integration tests for interactions, and UI tests for end-to-end validation, ensuring a robust codebase.

How do you handle version control in the CI/CD process, and which version control systems have you worked with?

Version control, particularly with Git, facilitates collaboration and code history tracking. Using branching strategies like GitFlow supports parallel development and ensures a stable main branch for CI/CD processes.

Describe the typical stages in a CI/CD pipeline for an Android project.

The Android CI/CD pipeline typically involves stages such as source code compilation, automated testing (unit, integration, and UI), code analysis (linting), artifact generation, and deployment to various environments (development, staging, production).

What are the benefits of using feature flags in the CI/CD process for Android apps?

Feature flags enable gradual feature rollouts, A/B testing, and quick rollbacks, reducing the impact of failures. They provide developers with control over feature releases and allow for experimentation without affecting the entire user base.

How do you manage dependencies in an Android project within a CI/CD pipeline?

Dependency management, often handled with Gradle, ensures consistent builds by defining and versioning dependencies. Utilizing dependency caching enhances build speed, and dependency locking prevents unexpected changes.

Explain the significance of automated deployment in the context of CI/CD for Android applications.

Automated deployment expedites the release process, minimizes manual errors, and promotes consistency across different environments. Blue-green deployments or canary releases ensure smooth transitions with minimal downtime.

Have you used containerization technologies like Docker in Android CI/CD, and if so, how?

Docker in Android CI/CD provides a reproducible build environment, enhancing consistency and portability. It allows packaging the application and its dependencies into containers, simplifying deployment across various platforms.

What is the importance of unit testing in the CI/CD workflow for Android development?

Unit testing in CI/CD verifies the correctness of individual functions or methods. It enhances code maintainability, provides rapid feedback to developers, and acts as a safety net against regressions during continuous integration.

Can you discuss a specific instance where CI/CD helped improve the development or deployment process of an Android application you worked on?

In a specific project, CI/CD streamlined our release process, significantly reducing deployment time. Additionally, automated testing in the pipeline detected critical issues early, leading to quicker resolutions and a more stable release. The overall result was improved software quality and a more responsive development cycle.

Thank you for reading my article. I really appreciate 👏 your response.

Clap if this article helps you. It means a lot to me. If I got something wrong, please comment for improve.
let’s connect on
Linkedin , GitHub

--

--