-
Notifications
You must be signed in to change notification settings - Fork 7
/
Jenkinsfile
42 lines (42 loc) · 1.7 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
40
41
42
pipeline {
agent any
parameters {
booleanParam(defaultValue: true, description: '', name: 'Build')
}
stages {
/*
stage ('Checkout') {
steps {
checkout scmGit(branches: [[name: '**']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/chiradip94/cicd-demo.git']])
}
}
*/
stage ('Build') {
when { expression { return params.Build }}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'pass', usernameVariable: 'user')]) {
sh "docker build -t ${user}/heloapp:${currentBuild.number} ."
sh "docker tag ${user}/heloapp:${currentBuild.number} ${user}/heloapp:latest"
}
}
}
stage ('Push to registry') {
when { expression { return params.Build }}
steps {
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'pass', usernameVariable: 'user')]) {
sh "docker login -u ${user} -p ${pass}"
sh "docker push ${user}/heloapp:${currentBuild.number}"
sh "docker push ${user}/heloapp:latest"
}
}
}
stage ('Deploy') {
steps {
sh "docker stop helloapp || true && docker rm helloapp || true"
withCredentials([usernamePassword(credentialsId: 'dockerhub', passwordVariable: 'pass', usernameVariable: 'user')]) {
sh "docker run -d -p 8085:8085 --name helloapp ${user}/heloapp:latest"
}
}
}
}
}