-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
84 lines (81 loc) · 2.37 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
pipeline {
agent {
label 'jenkins-slave'
}
environment {
registryCredential = 'dockerhub'
version = "1.0.1-$BUILD_NUMBER"
buildName = String.format("derrickwalton/slackbot:%s", version)
linuxBuild = ''
PYTHONPATH = "${WORKSPACE}"
}
stages {
stage('Setup'){
steps {
sh 'echo "Begin setup"'
notifyBuild('STARTED')
git 'https://github.com/plainenough/slackbot'
withCredentials([
file(credentialsId: 'k8sconfig', variable: 'kubeconfig')
]) {
sh 'cp $kubeconfig ../kubeconfig'
}
}
}
stage('testing') {
steps {
sh "kubectl --kubeconfig ../kubeconfig --insecure-skip-tls-verify get pods"
sh "pytest -v --junit-xml=results.xml"
}
}
stage('Build') {
steps {
sh 'echo "Begin build"'
script {
linuxBuild = docker.build(buildName, "-f ./container/Dockerfile --no-cache .")
}
}
}
}
post {
always {
junit testResults: 'results.xml', healthScaleFactor: 100
}
failure {
notifyBuild(currentBuild.result)
}
success {
lastChanges since: 'LAST_SUCCESSFUL_BUILD', format:'SIDE',matching: 'LINE'
script {
docker.withRegistry( '', registryCredential ) {
linuxBuild.push()
linuxBuild.push('latest')
}
}
sh "kubectl --kubeconfig ../kubeconfig --insecure-skip-tls-verify set image deployment/slackbot -n slackbot slackbot=derrickwalton/slackbot:\"${version}\""
notifyBuild(currentBuild.result)
}
}
}
def notifyBuild(String buildStatus = 'STARTED') {
buildStatus = buildStatus ?: 'SUCCESS'
def colorName = 'RED'
def colorCode = '#FF0000'
def channelName = '#jenkins_alerts' // This is where you would set your custom channel.
def details = """STARTED: Job ${env.JOB_NAME} ${env.BUILD_NUMBER}"""
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESS') {
color = 'GREEN'
colorCode = '#2E9022'
details = """SUCCESS (${env.BUILD_URL})"""
} else {
color = 'RED'
colorCode = '#FF0000'
details = """FAILED: Job ${env.JOB_NAME} ${env.BUILD_NUMBER}
Check console output at ${env.BUILD_URL}${env.JOB_NAME} ${env.BUILD_NUMBER}"""
}
// Send notifications
slackSend (color: colorCode, message: details, channel: channelName )
}