Commit 70319e62 authored by Muhammad Suleman's avatar Muhammad Suleman

Update Jenkinsfile

parent 2b98ed9c
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
pipeline {
agent any
stages {
stage('Checkout') {
steps {
......@@ -10,17 +20,43 @@ pipeline {
stage('Build and Create Docker Image') {
steps {
script {
def branchName = currentBuild.displayName
def imageName
if (branchName == 'dev') {
imageName = 'sulemantalpur6/frontend:dev'
} else if (branchName == 'QA') {
imageName = 'sulemantalpur6/frontend:QA'
} else if (branchName == 'UAT') {
imageName = 'sulemantalpur6/frontend:UAT'
} else if (branchName == 'master') {
imageName = 'sulemantalpur6/frontend:master'
} else {
echo "Branch $branchName not configured for Docker image build."
currentBuild.result = 'FAILURE'
return
}
sh 'npm install'
sh 'npm run build'
sh 'docker build -t sulemantalpur6/frontend:latest .'
sh "docker build -t $imageName ."
}
}
}
stage('Push Docker Image to Docker Hub') {
steps {
script {
def branchName = currentBuild.displayName
if (branchName == 'dev' || branchName == 'QA' || branchName == 'UAT' || branchName == "master") {
withCredentials([usernamePassword(credentialsId: 'dockerHub', usernameVariable: 'DOCKER_HUB_USERNAME', passwordVariable: 'DOCKER_HUB_PASSWORD')]) {
sh "docker login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD"
sh "docker push sulemantalpur6/frontend:latest" }
sh "docker push sulemantalpur6/frontend:$branchName"
}
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment