This repository has been archived by the owner on Oct 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Jenkinsfile
59 lines (50 loc) · 1.81 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
String cron_string = BRANCH_NAME == "master" ? "@daily" : ""
pipeline {
options { timeout(time: 1, unit: 'HOURS') }
triggers { cron(cron_string) }
environment {
GENERATOR = 'quay.io/ocpmetal/assisted-ignition-generator'
SLACK_TOKEN = credentials('slack-token')
}
agent {
node {
label 'centos_worker'
}
}
stages {
stage('build') {
steps {
sh 'make build-image'
}
}
stage('publish images on push to master') {
when {
branch 'master'
}
steps {
withCredentials([usernamePassword(credentialsId: 'ocpmetal_cred', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh '''docker login quay.io -u $USER -p $PASS'''
}
sh '''docker tag ${GENERATOR} ${GENERATOR}:latest'''
sh '''docker tag ${GENERATOR} ${GENERATOR}:${GIT_COMMIT}'''
sh '''docker push ${GENERATOR}:latest'''
sh '''docker push ${GENERATOR}:${GIT_COMMIT}'''
}
}
}
post {
always {
script {
if ((env.BRANCH_NAME == 'master') && (currentBuild.currentResult == "ABORTED" || currentBuild.currentResult == "FAILURE")){
stage('notify master branch fail') {
script {
def data = [text: "Attention! assisted-ignition-generator branch test failed, see: ${BUILD_URL}"]
writeJSON(file: 'data.txt', json: data, pretty: 4)
}
sh '''curl -X POST -H 'Content-type: application/json' --data-binary "@data.txt" https://hooks.slack.com/services/${SLACK_TOKEN}'''
}
}
}
}
}
}