-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
75 lines (65 loc) · 2.22 KB
/
Jenkinsfile
File metadata and controls
75 lines (65 loc) · 2.22 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
pipeline {
environment{
dockerimg = ""
}
agent any
stages {
stage('Clone Git ') {
steps {
git 'https://github.com/utkarsh78/Calculator_MiniProject.git'
}
}
stage('Maven Build') {
steps {
sh 'mvn clean install'
}
}
stage('Build Docker') {
steps {
script {
dockerimg = docker.build "utkarsh67/dockerimage_calminipro:latest"
}
}
}
stage('Push Docker Image'){
steps {
script {
docker.withRegistry('','DockerID'){
dockerimg.push()
}
}
}
}
stage('Delete Docker Image'){
steps {
script {
sh '''
# Get the IDs of images with the tag <none>
NONE_IMAGES=$(docker images | grep "<none>" | awk '{print $3}')
# Delete the containers associated with the <none> images
for IMAGE in $NONE_IMAGES
do
# Get the container IDs corresponding to image
CONTAINER_IDS=$(docker ps -a | grep $IMAGE | awk '{print $1}')
for CON_ID in $CONTAINER_IDS
do
docker rm --force $CON_ID
done
# Delete all of the <none> images
for IMAGE in $NONE_IMAGES
do
docker rmi --force $IMAGE
done
done
'''
}
}
}
stage('Pull Docker Image to Ansible User'){
steps {
//ansiblePlaybook becomeUser: null, colorized: true, disableHostKeyChecking: true, inventory: 'inventory', playbook: 'calminipro.yml'
ansiblePlaybook disableHostKeyChecking: true, credentialsId: 'InventoryID', inventory: 'inventory', playbook: 'calminipro.yml'
}
}
}
}