-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
78 lines (74 loc) · 2.62 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
def skipBranchBulds = true
if ( env.CHANGE_URL ) {
skipBranchBulds = false
}
TestsReport = '| Test name | Status |\\r\\n| ------------- | ------------- |'
testsReportMap = [:]
void makeReport() {
for ( test in testsReportMap ) {
TestsReport = TestsReport + "\\r\\n| ${test.key} | ${test.value} |"
}
}
pipeline {
environment {
AUTHOR_NAME = sh(script: "echo ${CHANGE_AUTHOR_EMAIL} | awk -F'@' '{print \$1}'", , returnStdout: true).trim()
}
agent {
label 'micro-amazon'
}
stages {
stage('Run API tests') {
when {
expression {
!skipBranchBulds
}
}
agent {
label 'docker-32gb'
}
steps {
script {
if ( AUTHOR_NAME == 'null' ) {
AUTHOR_NAME = sh(script: "git show -s --pretty=%ae | awk -F'@' '{print \$1}'", , returnStdout: true).trim()
}
testsReportMap['api-tests'] = 'failed'
}
sh '''
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit
'''
script {
testsReportMap['api-tests'] = 'passed'
}
}
}
}
post {
always {
script {
if (env.CHANGE_URL) {
withCredentials([string(credentialsId: 'GITHUB_API_TOKEN', variable: 'GITHUB_API_TOKEN')]) {
makeReport()
sh """
curl -v -X POST \
-H "Authorization: token ${GITHUB_API_TOKEN}" \
-d "{\\"body\\":\\"${TestsReport}\\"}" \
"https://api.github.com/repos/\$(echo $CHANGE_URL | cut -d '/' -f 4-5)/issues/${CHANGE_ID}/comments"
"""
}
}
}
sh '''
sudo docker rmi -f \$(sudo docker images -q) || true
sudo rm -rf ./*
'''
deleteDir()
}
failure {
script {
slackSend channel: '#cloud-dev-ci', color: '#FF0000', message: "[${JOB_NAME}]: build ${currentBuild.result}, ${BUILD_URL} owner: @${AUTHOR_NAME}"
}
}
}
}