forked from choxx/samarth-devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
39 lines (36 loc) · 1.17 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
node() {
withCredentials([string(credentialsId: 'docker_server', variable: 'docker_server')]) {
properties([
parameters([
string(name: 'docker_repo', defaultValue: 'samagragovernance/esamwad-backend', description: 'Docker Image Name'),
string(name: 'docker_server', defaultValue: "$docker_server", description: 'Docker Registry URL'),
])
])
}
stage('Checkout') {
cleanWs()
checkout scm
env.commit_id = env.BRANCH_NAME
echo "${env.commit_id}"
}
stage('docker-build') {
sh '''
docker build -t $docker_server/$docker_repo:$commit_id app/
'''
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
sh '''
docker build -t $docker_server/$docker_repo:latest app/
'''
}
}
stage('docker-push') {
sh '''
docker push $docker_server/$docker_repo:$commit_id
'''
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
sh '''
docker push $docker_server/$docker_repo:latest
'''
}
}
}