0% found this document useful (0 votes)
107 views2 pages

Jenkinsfile

The Jenkins pipeline contains 7 stages: 1) Git Checkout to pull code from a GitHub repo, 2) UNIT Testing using Maven, 3) Integration testing using Maven, 4) Maven Build, 5) SonarQube analysis for quality, 6) check the Quality Gate status, 7) upload the war file to a Nexus repository. Additionally, it builds a Docker image, tags it, and pushes the image to DockerHub.

Uploaded by

Sudharshanan AH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views2 pages

Jenkinsfile

The Jenkins pipeline contains 7 stages: 1) Git Checkout to pull code from a GitHub repo, 2) UNIT Testing using Maven, 3) Integration testing using Maven, 4) Maven Build, 5) SonarQube analysis for quality, 6) check the Quality Gate status, 7) upload the war file to a Nexus repository. Additionally, it builds a Docker image, tags it, and pushes the image to DockerHub.

Uploaded by

Sudharshanan AH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

pipeline {

agent any

stages{

stage('Git Checkout'){

steps{
git branch: 'main', url: 'https://github.com/vikash-kumar01/demo-
counter-app.git'
}
}
stage('UNIT Testing'){

steps{
sh 'mvn test'
}
}
stage('Integration testing'){

steps{
sh 'mvn verify -DskipUnitTests'
}
}
stage('Maven Build'){

steps{
sh 'mvn clean install'
}
}
stage('SonarQube analysis'){
steps{
script{
withSonarQubeEnv(credentialsId: 'sonar-api') {
sh 'mvn clean package sonar:sonar'
}
}
}
}
stage('Quality Gate status'){

steps{

script{

waitForQualityGate abortPipeline: false, credentialsId: 'sonar-


api'
}
}
}
stage('upload war file to nexus'){

steps{

script{

def readPomVersion = readMavenPom file: 'pom.xml'


def nexusRepo = readPomVersion.version.endsWith("SNAPSHOT") ?
"demoapp-snapshot" : "demoapp-release"

nexusArtifactUploader artifacts:
[
[
artifactId: 'springboot',
classifier: '', file: 'target/Uber.jar',
type: 'jar'
]
],
credentialsId: 'nexus-auth',
groupId: 'com.example',
nexusUrl: '3.234.253.249:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: nexusRepo,
version: "${readPomVersion.version}"
}
}
}
stage('Docker Image Build'){

steps{

script {
sh 'docker image build -t $JOB_NAME:v1.$BUILD_ID .'
sh 'docker image tag $JOB_NAME:v1.$BUILD_ID
vikashashoke/$JOB_NAME:v1.$BUILD_ID'
sh 'docker image tag $JOB_NAME:v1.$BUILD_ID
vikashashoke/$JOB_NAME:latest'
}
}
}

stage('push image to the dockerHUb'){

steps{

script{

withCredentials([string(credentialsId: 'dockerhub_creds',
variable: 'dockerhub_creds')]) {

sh 'docker login -u vikashashoke -p ${dockerhub_creds}'


sh 'docker image push vikashashoke/$JOB_NAME:v1.$BUILD_ID'
sh 'docker image push vikashashoke/$JOB_NAME:latest'
}
}
}
}
}
}

You might also like