Github only CICD challenge!

Subscribe to my newsletter and never miss my upcoming articles

Challenge: To host a simple CICD Pipeline on Github. No external CI or CD tools needed.

Pre-requisites: Java, Apache Maven, Git & Github, IDE of your choice, I'll be using VS Code. Make sure you have Java and Apache Maven installed and running on your machine.

Difficulty level: Medium

Link to my CICD Repository

We'll be covering five major steps to complete our challenge.

0. Introduction

What is CI/CD?

CICD stands for Continuous Integration and Continuous Delivery. Shipping software fast is one of the important areas of concern for Tech Companies. With the evolution of DevOps culture and adopting CICD Pipelines to ship software in minutes is a blessing for every product development team.

  1. Continuous Integration/CI:

Quoting the definition of CI from Atlassian

Continuous integration (CI) is the practice of automating the integration of code changes from multiple contributors into a single software project. The CI process is comprised of automatic tools that assert the new code’s correctness before integration. A source code version control system is the crux of the CI process. The version control system is also supplemented with other checks like automated code quality tests, syntax style review tools, and more.

  1. Continuous Delivery/CD: Quoting the definition of CD from Atlassian

Continuous delivery is an approach where teams release quality products frequently and predictably from source code repository to production in an automated fashion.

Plan of action

In order to get a brief overview of what we are building, we will be using Java as our programming language. We'll be taking care of the builds and test cases with Apache Maven. To automate all of the processes involved, we will use Github Actions. To store our snapshot(JAR), we will use Github Packages. This gets us to the following list.

  • Programming Language: Java
  • Build Tool: Apache Maven
  • Workflow Automation: Github Actions
  • Artifact Repository: Github Packages

1. Environment and Project Setup

To get started with our project, we need to perform the following steps.

Initializing a Java-Maven Project

To start a Java-Maven Project, navigate to your preferred directory and run the following command, this will create a Maven Project with default settings. Replace {group} and {project} with your preferred names.

mvn archetype:generate -DgroupId={group} -DartifactId={project} -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

Screenshot (35).png We will be initializing a git-repository inside this project. So run the following command

cd {project directory} && git init

We'll verify our project initialization by building it locally. To build the Maven project run the following maven commands.

Clean the environment

mvn clean

Compile the source-code

mvn compile

Package the source code into an executable binary (.JAR)

mvn install

Screenshot (37).png

Screenshot (38).png You should now see a target directory residing at the root-level of our project.

2. Getting started with Github and it's services

Adding a remote repository

Create a repository on Github and add it as a remote to the current project.

Screenshot (30).png

git remote add origin {link to repository}

Updating POM.xml & settings.xml

Add the following configuration tags to your POM.xml inside the <project> tag.

     <name>GitHub OWNER Apache Maven Packages</name>

Head towards your Maven's settings.xml file and add the following configurations. You can find it in your {maven.home}/conf/settings.xml directory.


Github Actions

To have a general idea of what Github Actions are, I suggest you go through the official document. Now, head to the Actions section inside your repository and search for Publish Java Package with Maven Action. Edit the default workflow with the following changes.

name: Maven Package

on: [push]


    runs-on: ubuntu-latest

    - uses: actions/checkout@v2
    - name: Set up JDK 13.0.1
      uses: actions/setup-java@v1
        java-version: 13.0.1
        server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
        settings-path: ${{ github.workspace }} # location for the settings.xml file

    - name : Validate
      run : mvn -B validate --file pom.xml

    - name : Compile
      run : mvn -B compile --file pom.xml

    - name : Test
      run : mvn -B test --file pom.xml

    - name: Package
      run: mvn -B package --file pom.xml

   - name: Maven Deploy
      run: mvn -B deploy
           GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN }}

Github Secrets Go to your profile section on Github and generate a new secret variable named DEPLOY_TOKEN and assign read/write packages permissions.

4. Test run

Make a change to your Java source code and push the changes to the remote repository, you should see your Github Actions workflow triggered automatically.

Screenshot (29).png

Screenshot (40).png

Congrats we've successfully deployed our Binary to Github Packages using Github Actions.

Silvi Sharma's photo

Well Explained!! Good Job👏

ayoosh pandey's photo

Great job mate 👍

Nishkarsh Raj's photo

Bhaiya humko bhi sikhao na!

Abhijeet Prasad's photo

aapse hi seekh k waapas aapko? haha! Thank you Sir!

Siddhant Gupta's photo

What a work bro!! It's just awesome

Abhijeet Prasad's photo

Thank you brother!

Shlok Mohanty's photo

ohh very cool bhaiya its a very good motivation to start building as well as testing and automating the build processes i think it will really help me and others in future thanks for the blog

Muskaan Madan's photo

Amazing work Abhijeet👍🏻

Abhijeet Prasad's photo

Thank you Muskaan!