-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
115 lines (114 loc) · 5.74 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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
pipeline{
agent{
label "docker && linux"
}
environment {
registry = "xuvin/caliver"
registryCredential = 'docker-xuvin-cred'
pushOverAPIUserKey = credentials('po-userkey')
pushOverAPIAPPToken = credentials('jenkins-po-key')
repoUSER = "kovidgoyal"
repoNAME = "calibre"
repoPATH = "${repoUSER}/${repoNAME}"
newVersion = "PLACEHOLDER"
}
stages{
stage("Clone"){
steps{
script{
newVersion = sh(label: 'Get Latest Release Version',script: 'curl --silent "https://api.github.com/repos/${repoPATH}/releases" | grep \'"tag_name":\' | sed -E \'s/.*"([^"]+)".*/\\1/\' | cut -c 2- | awk \'NR==1{print $1}\'', returnStdout: true).trim()
}
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL} for Version ${newVersion}.0"
// checkout scm
git 'https://github.com/demenzio/docker.CaliVer.git'
}
post{
success{
echo "====> Clone - Success"
}
failure{
echo "====> Clone - Failure"
}
}
}
stage("Build"){
steps{
sh (label: "Building Container ${registry}:${newVersion}.0", script: "docker build --pull --no-cache -t ${registry}:${newVersion}.0 .")
}
post{
success{
echo "====> Build - Success"
}
failure{
echo "====> Build - Failure"
}
}
}
stage("Test"){
steps{
sh (label: "Starting Test Container of ${registry}:${newVersion}", script: "docker run -it -d --name test-build${env.BUILD_ID}-calibre ${registry}:${newVersion}.0 /bin/bash")
sh (label: "Execute Test Command in ${registry}:${newVersion}", script: "docker exec test-build${env.BUILD_ID}-calibre bash -c 'calibre --version'")
//VERSION COMPARISON STILL MISSING
//sh (label: "Stopping Test Container of ${registry}:${newVersion}", script: 'docker stop $(docker ps -q -a)')
sh (label: "Stopping Test Container of ${registry}:${newVersion}", script: "docker stop test-build${env.BUILD_ID}-calibre")
}
post{
cleanup{
//sh (label: "Removing Test Containers of ${registry}", script: 'docker rm $(docker ps -q -a)')
sh (label: "Removing Test Containers of ${registry}", script: "docker rm -f test-build${env.BUILD_ID}-calibre")
}
success{
echo "====> Test Passed"
}
failure{
echo "====> Test failed"
}
}
}
stage("Push"){
steps{
script{
docker.withRegistry( '', 'docker-xuvin-cred' ) {
sh (label: "Tagging ${registry}:${newVersion}.0 as latest", script: "docker tag ${registry}:${newVersion}.0 ${registry}:latest")
sh (label: "Pushing ${registry}:${it}-${newVersion} as latest to Docker Hub", script: "docker push ${registry}:${newVersion}.0 && docker push ${registry}:latest")
}
}
}
post{
success{
echo "====> Push - Success"
}
failure{
echo "====> Push - Failure"
}
}
}
stage("Clean Up"){
steps{
//sh (label: "Remove Created Docker Images with Tag ${newVersion}", script: 'docker rmi -f $(docker images -aqf "reference=${registry}")')
sh (label: "Remove Created Docker Images with Tag ${newVersion}.0", script: "docker rmi -f ${registry}:${newVersion}.0 && docker rmi -f ${registry}:latest")
}
post{
success{
echo "====> Cleaned Up - Success"
}
failure{
echo "====> Cleaned up - Failure"
}
}
}
}
post{
success{
sh (label: 'Sending Notification with Status 0', script: 'curl -s --form-string "token=${pushOverAPIAPPToken}" --form-string "user=${pushOverAPIUserKey}" --form-string "priority=0" --form-string "title=${registry} - Status 0" --form-string "message=Build for ${registry} - Completed" https://api.pushover.net/1/messages.json', returnStdout: true)
}
failure{
sh (label: 'Sending Notification with Status 2', script: 'curl -s --form-string "token=${pushOverAPIAPPToken}" --form-string "user=${pushOverAPIUserKey}" --form-string "priority=2" --form-string "retry=30" --form-string "expire=10800" --form-string "title=${registry} - Status 2" --form-string "message=Build for ${registry} - Failure" https://api.pushover.net/1/messages.json', returnStdout: true)
sh (label: "Removing all created images of ${registry}", script: "docker rmi -f ${registry}:${newVersion}.0 && docker rmi -f ${registry}:latest || exit 0")
}
aborted{
sh (label: 'Sending Notification with Status 1', script: 'curl -s --form-string "token=${pushOverAPIAPPToken}" --form-string "user=${pushOverAPIUserKey}" --form-string "priority=1" --form-string "title=${registry} - Status 1" --form-string "message=Build for ${registry} - Aborted" https://api.pushover.net/1/messages.json', returnStdout: true)
sh (label: "Removing all created images of ${registry}", script: "docker rmi -f ${registry}:${newVersion}.0 && docker rmi -f ${registry}:latest || exit 0")
}
}
}