This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
forked from JavierCVilla/jenkins-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DockerPushUbuntu.groovy
84 lines (70 loc) · 4.1 KB
/
DockerPushUbuntu.groovy
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
#!groovy
def repoName = 'rootproject/root-ubuntu16'
node('docker-host') {
timestamps {
def stagingName = "rootbuild-${java.util.UUID.randomUUID()}"
git 'https://github.com/root-project/rootspi.git'
dir('docker/ubuntu16') {
try {
def ccacheVolumeName = "root-ccache-ubuntu16-native-Release-$branch"
stage('Build') {
dir('root-build') {
dir('roottest') {
git url: 'https://github.com/root-project/roottest.git', branch: branch
}
dir('root') {
git url: 'https://github.com/root-project/root.git', branch: branch
}
dir('rootspi') {
git url: 'https://github.com/root-project/rootspi.git'
}
}
sh "docker volume create $ccacheVolumeName"
sh "docker pull rootproject/root-ubuntu16-base"
sh "docker build -t $stagingName --build-arg uid=\$(id -u \$USER) ."
sh "HOME=\$(pwd) && docker run -t --name='$stagingName' -v $ccacheVolumeName:/ccache -v \$(pwd)/root-build:/root-build $stagingName /build.sh ubuntu16 native Release"
def testThreshold = [[$class: 'FailedThreshold',
failureNewThreshold: '0', failureThreshold: '0', unstableNewThreshold: '0',
unstableThreshold: '0'], [$class: 'SkippedThreshold', failureNewThreshold: '',
failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']]
step([$class: 'XUnitBuilder',
testTimeMargin: '3000', thresholdMode: 1, thresholds: testThreshold,
tools: [[$class: 'CTestType',
deleteOutputFiles: true, failIfNotNew: false, pattern: 'root-build/Testing/*/Test.xml',
skipNoTestFiles: false, stopProcessingIfError: true]]])
if (currentBuild.result == 'FAILURE') {
throw new Exception("Test results failed the build")
}
}
stage('Push') {
sh "HOME=\$(pwd) && docker commit --change='CMD [\"root.exe\"]' $stagingName '$repoName:$tag'"
withCredentials([usernamePassword(credentialsId: 'root_dockerhub_deploy_user', passwordVariable: 'password', usernameVariable: 'username')]) {
sh "HOME=\$(pwd) && docker login -u '$username' -p '$password'"
}
sh "HOME=\$(pwd) && docker push $repoName:$tag"
if (params['latestTag']) {
sh "HOME=\$(pwd) && docker tag $repoName:$tag $repoName:latest"
sh "HOME=\$(pwd) && docker push $repoName:latest"
}
}
} catch (e) {
println 'Build failed because:'
println e
currentBuild.result = 'FAILURE'
} finally {
// Build back to green
if (currentBuild.result == 'SUCCESS' && currentBuild.previousBuild?.result != 'SUCCESS') {
mattermostSend color: 'good', message: 'Docker build is back to green!'
}
// Build just failed
if (currentBuild.result != 'SUCCESS' && currentBuild.previousBuild?.result == 'SUCCESS') {
mattermostSend color: 'danger', message: "Docker build [just failed](${currentBuild.absoluteUrl})"
}
// Remove containers/cleanup
sh "HOME=\$(pwd) && docker rm -f \$(docker ps -a -f name=$stagingName -q)"
sh "HOME=\$(pwd) && docker rmi -f $stagingName"
sh "HOME=\$(pwd) && docker rmi -f $repoName:$tag"
}
}
}
}