Jenkins

Jenkins is an automated CI/CD Tool where CI stands for Continuous Integration and CD stands for Continuous delivery. It helps automate the parts of software development related to building, testing, and deploying. In simple word you can say it as "Click a button SHOW". Jenkins helps with lot of functionality like building code ,compiling code , adding necessary tests and has great features. It has very reliable connections with lots of other technologies and can be used with their PLUGINS.

Basically , Jenkins is use to do smooth and quick deployment. We can deploy it to local machine or we can deploy to on premises data center or any cloud. Jenkins takes your code any sort of code such as python, java or go or JS etc and compiles it using different compiler such as MAVEN one of the most used compiler and then builds your code in some war or Zip or as a docker Image. Finally once everything is built properly it deploy as an when required .

Some Common terms and need of them.

  1. Jenkins file: You can either use Jenkins Job directly or you can use Jenkins file in which you define your steps i.e whatever you want to do.
  2. Jenkins Jobs: Mostly people nowadays are using pipeline Jobs and earlier it use to be Freestyle Jobs. Pipeline Jobs provide much effective stages /steps to incorporate and use.
  3. Plugins: We need to use certain plugins in order to accomplish our successful deployments. For EX: we have AWS plugins, Docker, bit bucket, GIT and many more. Once we install those plugins using Manage Jenkins option these gets integrated with Jenkins.
  4. Credentials: This is very important for everyone to focus on. In order to connect to your repositories or AWS or any server or anywhere you would need some sort of authentication method through which you can access them. You can either use username and Password , SSH keys ( to access Linux Machine or AWS Ec2 ) , Docker Hub credentials to pull or push images and ACCESS KEY and SECRET KEYS for most of AWS services.
  5. USER: As soon as your login to Jenkins for the first time you are provided with admin ( username and password) but your all jobs run as JENKINS user and you can change if required.

EXAMPLE OF JENKINS FILE deploying Terraform code :

pipeline {
  agent any
stages {
  stage('Pull content') {
   steps {
    echo "DEPLOYING CLOUD INFRA | Job: ${env.JOB_NAME} | Build number ${env.BUILD_NUMBER}"
    git 'git@bitbucket.org:/XXXX/XXXXXXXX/XXXXXXXXXXXX'
      }
    }

  stage('User') {
   steps {
    sh 'whoami'
      }
    } 

  stage('Install TF Dependencies') {
   steps {
    sh "sudo  apt install wget zip python-pip -y"
    sh "cd /tmp"
    sh "curl -o terraform.zip 
     https://releases.hashicorp.com/terraform/0.12.5/terraform_0.12.5_linux_amd64.zip"
     sh "unzip -o terraform.zip"
     sh "sudo mv terraform /usr/bin"
     sh "rm -rf terraform.zip"
      }       
   }

  stage('Terraform Version') {
   steps {
    sh "sudo terraform -version"
     }
   } 

  stage('Initialise Terraform') {
   steps {
    dir("Project/Elasticbeanstalk-applications/Wrapper") {
    sh "sudo terraform init"
      }   
     }
   }

  stage('Terraform Plan') {
    steps {
     dir("Project/Elasticbeanstalk-applications/Wrapper") {
    sh "sudo terraform plan"
       }   
     }
   }
 stage('Terraform Apply') {
  steps {
    dir("Project/Elasticbeanstalk-applications/Wrapper") {
    sh "sudo terraform apply -input=false -auto-approve"
       }   
     }
  }
  }
 post {
   success {
       echo " Status: PIPELINE ${currentBuild.result} | Job: ${env.JOB_NAME} | Build number ${env.BUILD_NUMBER}"
           }
   failure {
       echo " Status: PIPELINE ${currentBuild.result} | Job: ${env.JOB_NAME} | Build number ${env.BUILD_NUMBER}"
           }
   aborted {
       echo " Status: PIPELINE ${currentBuild.result} | Job: ${env.JOB_NAME} | Build number ${env.BUILD_NUMBER}"
          }
     }
}

Advertisement