CICD process for deploying Java Maven project using Git + Jenkins + S3
- pradeepmaiya97
- May 17, 2020
- 4 min read
We all have come across this word "CICD" what does it mean?
it stands for Continuous Integration & Continuous Delivery or Continuous Deployment, it lays out some practices to follow in order for the code you write to more quickly and safely get to your users and ultimately offers more productivity.
Prerequisites for this setup:
Jenkins is an open source automation tool written in Java with plugins built for Continuous Integration purpose. Jenkins is used to build and test your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. So basically it eliminates all the redundant process the developers have to go through to build or deploy their projects.
Git is a type of version control system (VCS) that makes it easier to track changes to files. For example, when you edit a file, git can help you determine exactly what changed, who changed it.
An Amazon s3 bucket is a public cloud storage resource available in Amazon Web Services' (AWS) Simple Storage Service (s3), an object storage offering. Amazon s3 buckets, which are similar to file folders, store objects, which consist of data and its descriptive metadata.
How to carry out CICD using these above tools?
Let’s consider you have a java maven project which on your github/gitlab. And you need deploy this project in a particular environment. The conventional way would include
Cloning that project in that environment
Build the project to a deployable format (ex:.JAR, .WAR, .exe etc)
Setting up all the dependencies for the project to run
Then finally deploy the project in the specified location.
The problem with this approach is while managing your version control i.e, if you update or modify your code on Git. You have to carry out the entire process again manually.
Now for the smarter approach:
Let’s say you have configured a Jenkins job (one time process), where you map your Git repository and build conditions and post build you can specify where the build can be published (Ex. Lets say an AWS ec2 server or s3 bucket in our case) Then you can map a trigger to run this job whenever there is a change in the Git repository. So now there is no need for human intervention for build and deployment.
Let’s see how we can Setup Jenkins.
Visit "https://www.jenkins.io/download/" link , there scroll down you will find for various operating systems(make sure you download the stable version of it), click on the operating system name to start downloading. (OR)
Download stable version of "Jenkins.war" file from "https://updates.jenkins-ci.org/download/war/" and after downloading, open command prompt and type "java -jar jenkins.war" to start server.
Once server is up open browser and type "localhost:8080" to open Jenkins UI.
First thing it will ask for "Administrator password" which will be stored in "C:\Users\{USERNAME}\.jenkins\secrets\initialAdminPassword" copy it and paste it in text-box.
Next up it will ask for "Customize Jenkins" where you need to select one out of two options, make sure you select option named "install suggested plugins", it will download the set of defaults plugins on behalf of you.
Later you are landed into "Create First Admin User" page where you have options to create a user(Admin user is the user which you will create), click on "Save and finish" to finish the setup.
Finish setup process by clicking on "Start using Jenkins".
Now you have officially started your Jenkins server and created admin user for it. Now that you done that lets look into main process of how to setup CICD pipeline using Git and AWS s3.
Inside Jenkins click on "Manage Jenkins" and navigate to "Manage plugins" section to install the "s3 Publisher" plugin which is required for storing the artifact to s3 bucket. Search for "s3 publisher" select it and click on "install without restart".

Then click on "Manage Jenkins" and navigate to "Global Tool Configuration", in that find "Maven" and "JDK" for setting the path, if they are not present in local just check "Install automatically" option by giving accurate versions, click on "Apply" to apply the changes and finally "Save" the change.


Later navigate to "Manage Jenkins" > "Configure System" scroll till where you will find "Amazon s3 profiles" there click on "Add", for "Profile name" give random name, and for "Access key" & "Secret key" make sure you have "AWS" account , where you can find on "My Securitty Credentials". Where you can view only "accessKey" , in order to view "SecretKey" make sure you create new one or you have "AWS cli" configured locally in order to view keys stored locally. After setting click on "Apply" later "Save".


Its time to create job by clicking on "New Item", provide name, select "Freestyle project" and click "ok".

Now inside job, under "General" select "GitHub project" and give the git URL where your maven project exists. Replicate same under "Source Code Management" as well.


Then, scroll down to "Build" and select "Invoke top-level Maven targets" for "Maven Version" select the name which was created earlier, "under setting up Jenkins for CICD process", for "Goals" give command like "clean install".

Finally, scroll to "Post-build Actions" and select "publish artifacts to s3 bucket", under which provide information's like "Files to upload", provide bucket name, region under which its present. Click "Apply" and "Save", click on "Build now" option to run your job.

That's it!!! the build artifact is stored in given s3 bucket.
Comments