forked from openshift/assisted-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
125 lines (109 loc) · 5.17 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
124
125
String cron_string = BRANCH_NAME == "master" ? "@hourly" : ""
pipeline {
agent { label 'centos_worker' }
triggers { cron(cron_string) }
environment {
SERVICE = 'ocpmetal/assisted-service'
ISO_CREATION = 'assisted-iso-create'
SLACK_TOKEN = credentials('slack-token')
}
options {
timeout(time: 1, unit: 'HOURS')
}
stages {
stage('Check environment') {
steps {
sh '''
if [ $(minikube status|grep Running)="" ] ; then
echo "minikube is not running on $NODE_NAME, failing job BUILD_URL"
echo '{"text":"minikube is not running on: ' > minikube_data.txt
echo ${NODE_NAME} >> minikube_data.txt
echo 'failing job: ' >> minikube_data.txt
echo ${BUILD_URL} >> minikube_data.txt
echo '"}' >> minikube_data.txt
curl -X POST -H 'Content-type: application/json' --data-binary "@minikube_data.txt" https://hooks.slack.com/services/$SLACK_TOKEN
sh "exit 1"
fi
'''
}
}
stage('clear deployment') {
steps {
sh 'docker image prune -a -f'
sh 'make clear-deployment'
}
}
stage('Build') {
steps {
sh '''export PATH=$PATH:/usr/local/go/bin; make build-image build-assisted-iso-generator-image'''
}
}
stage('Deploy for subsystem') {
steps {
withCredentials([usernamePassword(credentialsId: 'dockerio_cred', passwordVariable: 'PASS', usernameVariable: 'USER')]) {
sh '''docker login docker.io -u $USER -p $PASS'''
}
sh '''export PATH=$PATH:/usr/local/go/bin; make jenkins-deploy-for-subsystem'''
sh '''# Dump pod statuses;kubectl get pods -A'''
}
}
stage('Subsystem-test') {
steps {
sh '''export PATH=$PATH:/usr/local/go/bin;make subsystem-run'''
}
}
stage('clear deployment after subsystem test') {
steps {
sh 'make clear-deployment'
}
}
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 ${SERVICE} quay.io/ocpmetal/assisted-service:latest'''
sh '''docker tag ${SERVICE} quay.io/ocpmetal/assisted-service:${GIT_COMMIT}'''
sh '''docker push quay.io/ocpmetal/assisted-service:latest'''
sh '''docker push quay.io/ocpmetal/assisted-service:${GIT_COMMIT}'''
sh '''docker tag ${ISO_CREATION} quay.io/ocpmetal/assisted-iso-create:latest'''
sh '''docker tag ${ISO_CREATION} quay.io/ocpmetal/assisted-iso-create:${GIT_COMMIT}'''
sh '''docker push quay.io/ocpmetal/assisted-iso-create:latest'''
sh '''docker push quay.io/ocpmetal/assisted-iso-create:${GIT_COMMIT}'''
}
}
}
post {
failure {
script {
if (env.BRANCH_NAME == 'master')
sh '''
echo '{"text":"Attention! assisted-service master branch subsystem test failed, see: ' > data.txt
echo ${BUILD_URL} >> data.txt
echo '"}' >> data.txt
curl -X POST -H 'Content-type: application/json' --data-binary "@data.txt" https://hooks.slack.com/services/$SLACK_TOKEN
'''
}
echo 'Get assisted-service log'
sh '''
kubectl get pods -o=custom-columns=NAME:.metadata.name -A | grep assisted-service | xargs -r -I {} sh -c "kubectl logs {} -n assisted-installer > test_dd.log"
mv test_dd.log $WORKSPACE/assisted-service.log || true
'''
echo 'Get postgres log'
sh '''kubectl get pods -o=custom-columns=NAME:.metadata.name -A | grep postgres | xargs -r -I {} sh -c "kubectl logs {} -n assisted-installer > test_dd.log"
mv test_dd.log $WORKSPACE/postgres.log || true
'''
echo 'Get scality log'
sh '''kubectl get pods -o=custom-columns=NAME:.metadata.name -A | grep scality | xargs -r -I {} sh -c "kubectl logs {} -n assisted-installer > test_dd.log"
mv test_dd.log $WORKSPACE/scality.log || true
'''
echo 'Get createimage log'
sh '''kubectl get pods -o=custom-columns=NAME:.metadata.name -A | grep createimage | xargs -r -I {} sh -c "kubectl logs {} -n assisted-installer > test_dd.log"
mv test_dd.log $WORKSPACE/createimage.log || true
'''
}
}
}