-
Notifications
You must be signed in to change notification settings - Fork 459
/
Jenkinsfile
49 lines (49 loc) · 1.42 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
43
44
45
46
47
48
49
pipeline {
environment {
registry = 'sreeharshav/devopsb17'
registryCredential = 'dockerhub_id'
dockerSwarmManager = '10.40.1.26:2375'
dockerhost = '10.40.1.26'
dockerImage = ''
}
agent any
stages {
stage('Cloning our Git') {
steps {
git 'https://github.com/mavrick202/dockertest1.git'
}
}
stage('Building our image') {
steps {
script {
dockerImage = docker.build registry + ":v$BUILD_NUMBER"
}
}
}
stage('Push Image To DockerHUB') {
steps {
script {
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
}
}
}
}
stage('Cleaning up') {
steps {
sh "docker rmi $registry:v$BUILD_NUMBER"
}
}
stage('Deploying to Docker Swarm') {
steps {
sh "docker -H tcp://$dockerSwarmManager service rm testing1 || true"
sh "docker -H tcp://$dockerSwarmManager service create --name testing1 -p 8100:80 $registry:v$BUILD_NUMBER"
}
}
stage('Verifying The Deployment') {
steps {
sh 'curl http://$dockerhost:8100 || exit 1'
}
}
}
}