You should know Docker
, basic CI-CD concept
& basics of what Jenkins
is used for
You should have Linux OS
like Ubuntu, Java
(OpenJDK 11) & Docker
installed
This project was created to install Jenkins on a local machine (Ubuntu 16.04) and create a basic pipeline with GitHub & Docker
We will be doing is
- Installing Jenkins and running it, on a local machine
- Creating a docker image
- Pushing it to docker hub using Jenkins' pipeline
- Add repository keystream
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
You must get a response printed as OK
- Now add the Debian package to your
sources.list
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
- Now, update system
sudo apt update
- Finally, install Jenkins
sudo apt install jenkins
Now, Jenkins is installed in your system and is ready to run.
We would be using standard systemctl
commands
- To start
sudo systemctl start jenkins
- To check status
sudo systemctl status jenkins
- To stop
sudo systemctl stop jenkins
- To start on boot
sudo systemctl enable jenkins
-
Go to
<IP_ADDRESS>:8080
-
Jenkins login page should appear asking you to enter the administrator password
-
Now open a terminal and type
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
A string printed on the console is the administrator password, enter this is on Jenkins login page
-
Choose
Install selected plugins
(You may chooseSelect plugins to install
)
Now it will install plugins and show you the details, it takes some time -
It would ask you to create a new 'Admin User'.
Now, Jenkins is configured for the system
-
Go to
Manage Jenkins
from menu on the left pane -
Click on
Manage Plugins
-
Go to
Advance
tab -
Search & install
GitHub Integration
,Pipeline
,Docker
&Docker Pipeline
pluginsa. Click on
Download now and install after restart
b. On the next window select the checkbox for
Restart Jenkins when installation is complete and no jobs are running
at the bottom of the page. Jenkins will restart once plugin is downloaded -
Now go to your GitHub repository, go to
Settings
, go toWebhooks
, click onAdd Webhook
-
For the payload URL, provide your Jenkins URL and the GitHub webhook path at the end of the URL -
https://<JENKINS_URL>/github-webhook/.
-
Content type
should be JSON -
In
Which events would you like to trigger this webhook?
selectJust the push event.
Now we are ready to integrate any GitHub repository with Jenkins
-
On the dashboard, click on
Create Job
option -
Give name to your pipeline
-
Choose
Pipeline
-
In
Build Triggers
selectGitHub hook trigger for GITScm polling
-
In
Pipeline section
choose definition asPipeline script from SCM
-
In the
Source Code Management (SCM)
tab, selectGit
enter GitHub repository URL, and save -
Now copy Jenkinsfile in your repository base path
-
Add Docker credentials to Jenkins host
a. On the top right of home page, click on dropdown next to the username
b. Select
Credentials
c. Go to
System
OR Click onGlobal
from any one pre-existing credentialsd. Click on
Add Credentials
e. Keep scope
Global
f. Enter Docker Hub username & password and set some ID in ID field
-
Now in the
Jenkinsfile
in theenvironment
set the ID
The pipeline is now created, push code to GitHub to see the pipeline run