-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
123 lines (122 loc) · 5.08 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
116
117
118
119
120
121
122
123
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
environment {
registry = 'bitflowstream/bitflow-pipeline-python'
registryCredential = 'dockerhub'
dockerImage = '' // Variable must be declared here to allow passing an object between the stages.
dockerImageARM32 = ''
}
agent {
docker {
image 'bitflowstream/python-build:debian'
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('Git') {
steps {
script {
env.GIT_COMMITTER_EMAIL = sh(script: "git --no-pager show -s --format='%ae'", returnStdout: true).trim()
}
}
}
stage('Test') {
steps {
sh 'pip install -r requirements.txt'
sh 'py.test --junitxml test-report.xml --cov-report xml:coverage-report.xml --cov=bitflow tests'
}
post {
always {
junit 'test-report.xml'
archiveArtifacts '*-report.xml'
}
}
}
stage('SonarQube') {
steps {
script {
def scannerHome = tool 'sonar-scanner-linux'
withSonarQubeEnv('CIT SonarQube') {
sh """
${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=python-bitflow -Dsonar.branch.name=$BRANCH_NAME \
-Dsonar.sources=bitflow -Dsonar.tests=tests/. \
-Dsonar.inclusions="**/*.py" \
-Dsonar.python.coverage.reportPaths=coverage-report.xml \
-Dsonar.test.reportPath=test-report.xml
"""
}
}
timeout(time: 30, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Docker build') {
steps {
script {
dockerImage = docker.build registry + ':$BRANCH_NAME-build-$BUILD_NUMBER', '-f build/alpine.Dockerfile .'
sh "./build/test-image.sh $BRANCH_NAME-build-$BUILD_NUMBER"
dockerImageARM32 = docker.build registry + ':$BRANCH_NAME-build-$BUILD_NUMBER-arm32v7', '-f build/arm32v7.Dockerfile .'
sh "./build/test-image.sh $BRANCH_NAME-build-$BUILD_NUMBER-arm32v7"
}
}
}
stage('Docker push') {
when {
branch 'master'
}
steps {
script {
docker.withRegistry('', registryCredential) {
dockerImage.push("build-$BUILD_NUMBER")
dockerImage.push("latest-amd64")
dockerImageARM32.push("build-$BUILD_NUMBER-arm32v7")
dockerImageARM32.push("latest-arm32v7")
}
}
withCredentials([[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'dockerhub', usernameVariable: 'DOCKERUSER', passwordVariable: 'DOCKERPASS'
]]) {
// Dockerhub Login
sh 'echo "$DOCKERPASS" | docker login -u "$DOCKERUSER" --password-stdin'
sh "docker manifest create ${registry}:latest ${registry}:latest-amd64 ${registry}:latest-arm32v7"
sh "docker manifest annotate ${registry}:latest ${registry}:latest-arm32v7 --os linux --arch arm"
sh "docker manifest push --purge ${registry}:latest"
}
}
}
}
post {
success {
node('master') {
withSonarQubeEnv('CIT SonarQube') {
slackSend channel: '#jenkins-builds-all', color: 'good',
message: "Build ${env.JOB_NAME} ${env.BUILD_NUMBER} was successful (<${env.BUILD_URL}|Open Jenkins>) (<${env.SONAR_HOST_URL}|Open SonarQube>)"
}
}
}
failure {
node('master') {
slackSend channel: '#jenkins-builds-all', color: 'danger',
message: "Build ${env.JOB_NAME} ${env.BUILD_NUMBER} failed (<${env.BUILD_URL}|Open Jenkins>)"
}
}
fixed {
node('master') {
withSonarQubeEnv('CIT SonarQube') {
slackSend channel: '#jenkins-builds', color: 'good',
message: "Thanks to ${env.GIT_COMMITTER_EMAIL}, build ${env.JOB_NAME} ${env.BUILD_NUMBER} was successful (<${env.BUILD_URL}|Open Jenkins>) (<${env.SONAR_HOST_URL}|Open SonarQube>)"
}
}
}
regression {
node('master') {
slackSend channel: '#jenkins-builds', color: 'danger',
message: "What have you done ${env.GIT_COMMITTER_EMAIL}? Build ${env.JOB_NAME} ${env.BUILD_NUMBER} failed (<${env.BUILD_URL}|Open Jenkins>)"
}
}
}
}