DEV Community

Kenneth Atria
Kenneth Atria

Posted on • Edited on

16 9

Setting up a CI/CD with Jenkins

** What you need ? **

  • Dockerhub and Github Account
  • Server with linux setup. For this case ubuntu
  • Your application is already configured on your test instances
  • This tutorial assumes you have set up a Jenkins file in your project. View reference and make necessary changes

1. Installing Jenkins on your Server

sudo apt update

search of all available packages & pick one from the options
sudo apt search openjdk

For this case I will be using version 11, so
sudo apt install openjdk-11-jdk

Confirm installation with running version check
java -version

Now we are ready to install Jenkins. We start off by appending the Debian package repository address to the server's sources.list

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
/etc/apt/sources.list.d/jenkins.list'

We'll run update so that apt will use the new repo
sudo apt-get update

Installing Jenkins
sudo apt-get install jenkins=2.289.3

That's all

2. Setting up your Github and retrieving an API key

Login into your Github, and head over to your developer settings : Profile -> Settings -> Developer settings -> Personal access tokens

Note: I wouldn't consider this optional but it's good practice to set an expiration duration for your token.

Select admin:repo_hook

Screenshot 2021-08-06 at 07.38.06

Lastly set repo: *repo_status*. Jenkins likes to access the repo commit status

Screenshot 2021-08-06 at 07.33.21

Click "Generate token" and save your token somewhere.

3. Setting up Jenkins

3.1 Setting up an Administrator

1.SSH in your Jenkins instance
2.To retrieve your temporary password
sudo "cat /var/lib/jenkins/secrets/initialAdminPassword"
3.Visit <your-instance-ip:8080>
4.Paste retrieved password into Jenkins start up page.
5.Go ahead and set up a permanent admin user on Jenkins

3.2 Setting up your Jenkin Projects

1.Log into Jenkins

2.Set up credentials in Jenkins will use to login into servers.
Click Credentials -> click global -> click add credentials and input your instance username: deploy, password :+++++, id: webserver_login

3.Set up docker hub credentials too:
username: username, password :access-token, id: docker_hub_login

4.Set up global properties in Jenkins for staging server
Click "Manage Jenkins" - "Configure System" - "Global properties and select Environment Variables" -> Add
input "name: staging_ip" and "value:staging-ip-address"

5.Set up Jenkins project
Give your project a name -> Select Multibranch pipeline for project type

Under branch sources: click add source -> GitHub
Enter the details and use your GitHub access token as password and Github username as the username, set id e.g "github_key" and description

Select github_key for credentials
Input your GitHub name into owner field
Set repository as intended repo
Go a head and Save

Jenkins will scan your repo and run an initial build

Click Jenkins, In the project - click Master -> Build now

Next up

Powering up and down developer AWS instances using Slack and Jenkins

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay