Unverified Commit 64886356 authored by Tushar's avatar Tushar Committed by GitHub
Browse files

Update Jenkinsfile

No related merge requests found
Showing with 23 additions and 17 deletions
+23 -17
node() { node() {
properties([ withCredentials([string(credentialsId: 'docker_server', variable: 'docker_server')]) {
parameters([ properties([
string(name: 'docker_repo', defaultValue: 'user-service', description: 'Docker Image Name'), parameters([
string(name: 'docker_server', defaultValue: 'localhost:5000', description: 'Docker Registry URL'), string(name: 'docker_repo', defaultValue: 'samagragovernance/esamwad-user-service', description: 'Docker Image Name'),
string(name: 'docker_server', defaultValue: "$docker_server", description: 'Docker Registry URL'),
])
]) ])
]) }
stage('Checkout') { stage('Checkout') {
cleanWs() cleanWs()
checkout scm checkout scm
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim() env.commit_id = env.BRANCH_NAME
env.commit_id = sh(script: 'echo ' + env.docker_repo + '_' + commit_hash + '_' + env.BRANCH_NAME, returnStdout: true).trim()
echo "${env.commit_id}" echo "${env.commit_id}"
} }
stage('docker-build') { stage('docker-build') {
sh '''
docker build -f build/Dockerfile -t $docker_server/$docker_repo:$commit_id .
'''
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
sh ''' sh '''
docker build -f build/Dockerfile -t $docker_server/$docker_repo:$commit_id . docker build -f build/Dockerfile -t $docker_server/$docker_repo:$commit_id .
''' '''
}
} }
stage('docker-push') { stage('docker-push') {
sh ''' sh '''
docker push $docker_server/$docker_repo:$commit_id docker push $docker_server/$docker_repo:$commit_id
''' '''
} if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
stage('ArchiveArtifacts') { sh '''
sh("echo ${commit_id} > commit_id.txt") docker push $docker_server/$docker_repo:latest
archiveArtifacts 'commit_id.txt' '''
currentBuild.description = "${commit_id}" }
} }
} }
\ No newline at end of file
Supports Markdown
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