Jenkins
Jenkins is an open source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language. It is used to implement CI/CD workflows, called pipelines.
Pipelines automate testing and reporting on isolated changes in a larger code base in real time and facilitates the integration of disparate branches of the code into a main branch. They also rapidly detect defects in a code base, build the software, automate testing of their builds, prepare the code base for deployment (delivery), and ultimately deploy code to containers and virtual machines, as well as bare metal and cloud servers. There are several commercial versions of Jenkins. This definition only describes the upstream Open Source project.
Login into Jenkins
Navigate to localhost:8080 by default Jenkins will be run at this URL .Key in your credentials then you will be taken to the dashboard
Create a new job
While on the dashboard click on create a job
Configure the job
Give your job a name and select Pipeline after this click on okey .
You will be navigated to a configuration page. Select your build triggers.For this example we are going to pick GitHub since we want our build be in sync with git push .
On the pipeline script pick Pipelinescript from SCM and follow the below configuration remember to change your github repo URL and branch name
After all this steps press save
Exposing localhost:8080 using Ngrok
ngrok http http://localhost:8080
Github
In your github repo ensure you have a file called jenkins and it have a script . Example is below
pipeline {
agent any
environment {
DIRECTORY_PATH = "${env.WORKSPACE}"
TESTING_ENVIRONMENT = 'Staging'
PRODUCTION_ENVIRONMENT = 'Blackie360Production' // Customize the production environment name
}
stages {
stage('Build') {
steps {
script {
echo "Fetching the source code from the directory path: ${env.DIRECTORY_PATH}"
echo "Compiling the code and generating any necessary artifacts"
}
}
}
stage('Test') {
steps {
script {
echo "Running unit tests"
echo "Running integration tests"
}
}
}
stage('Code Quality Check') {
steps {
script {
echo "Checking the quality of the code"
}
}
}
stage('Deploy') {
steps {
script {
echo "Deploying the application to the testing environment: ${env.TESTING_ENVIRONMENT}"
}
}
}
stage('Approval') {
steps {
script {
echo "Waiting for manual approval..."
sleep(time: 10, unit: 'SECONDS') // Simulate approval with a sleep
}
}
}
stage('Deploy to Production') {
steps {
script {
echo "Deploying the application to the production environment: ${env.PRODUCTION_ENVIRONMENT}"
}
}
}
}
post {
always {
echo "Pipeline execution complete"
}
}
}
Create a web hook by going to the repo ->setting ->webhook ->add webhook
Here is an example of the configuration
After this now when one adds a commit and push the jenkins pipeline will run and do the build automatic if all check are passed
Console output
The console output shows the build was triggered by a GitHub push