-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
59 lines (52 loc) · 1.51 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
pipeline {
agent any
environment {
TAG = "${env.GIT_COMMIT.substring(0, 7)}-${env.BUILD_NUMBER}"
}
stages {
stage('audit-code') {
steps {
sh 'grype dir:src --fail-on medium'
}
}
stage('build') {
steps {
withCredentials([usernamePassword(
credentialsId: 'dockerhub-login',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)]) {
sh 'echo $PASSWORD | docker login -u $USERNAME --password-stdin'
}
sh "docker build -t janw4ld/go-serve:$TAG ."
}
}
stage('audit-image') {
steps {
sh "grype janw4ld/go-serve:$TAG --fail-on medium"
}
}
stage('push') {
steps {
sh "docker push janw4ld/go-serve:$TAG"
}
}
}
post {
failure {
slackSend(
botUser: true,
tokenCredentialId: 'slack-oauth-bot',
channel: '#ana-w-jenkins',
color: '#ff0000',
message: "job:${env.JOB_NAME}-${env.BUILD_NUMBER} failed :(" +
"\n @branch:${env.GIT_BRANCH}" +
"\n @commit:${env.GIT_COMMIT}"
)
}
always {
sh 'docker logout'
sh "docker rmi janw4ld/go-serve:$TAG"
}
}
}