-
Notifications
You must be signed in to change notification settings - Fork 15
/
Jenkinsfile
77 lines (68 loc) · 2.36 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
pipeline {
agent any
stages {
stage('Run tests') {
steps {
sh "docker run --rm -w \"${WORKSPACE}\" -v \"${WORKSPACE}:/${WORKSPACE}\" composer/composer install"
sh "docker run --rm -w \"${WORKSPACE}\" -e account_uid=${params.ACCOUNT_UID} -e project_id=${params.PROJECT_ID} -e user_id=${params.USER_ID} -e user_key=${params.USER_KEY} -v \"${WORKSPACE}:/${WORKSPACE}\" phpunit/phpunit:5.7.12 --log-junit tests-result.xml --coverage-clover tests-clover.xml --debug --verbose"
}
}
stage('Junit') {
steps {
junit 'tests-result.xml'
}
}
stage('Sonar') {
steps {
script {
String scannerHome = tool name: 'sonar', type: 'hudson.plugins.sonar.SonarRunnerInstallation';
withSonarQubeEnv('sonar') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.language=php -Dsonar.php.coverage.reportPath=tests-clover.xml -Dsonar.php.tests.reportsPath=tests-result.xml -Dsonar.sources=src -Dsonar.projectKey=\"${params.SONAR_PROJECT_KEY}\" -Dsonar.projectName=\"${params.SONAR_PROJECT_NAME}\" -Dsonar.projectVersion=${env.BUILD_NUMBER} -Dsonar.php.file.suffixes=\"php,php3,php4,php5,phtml,inc,module,install\" -Dsonar.exclusions=\"${params.SONAR_EXCLUDE_PATH}\""
}
}
}
}
stage("Quality Gate") {
steps {
script {
try {
timeout(time: 5, unit: 'MINUTES') {
def qg = waitForQualityGate()
if (qg.status != 'OK') {
error "Pipeline aborted due to quality gate failure"
}
}
}
catch (err) {
// Catch timeout exception but not Quality Gate.
String errorString = err.getMessage();
if (errorString == "Pipeline aborted due to quality gate failure") {
error errorString
}
}
}
}
}
stage('Clean up') {
steps {
deleteDir()
}
}
}
post {
unstable {
slackSend (
channel: "${params.SLACK_CHAT}",
color: 'bad',
message: "Tests failed: <${env.BUILD_URL}|${env.JOB_BASE_NAME} #${env.BUILD_NUMBER}>"
)
}
failure {
slackSend (
channel: "${params.SLACK_CHAT}",
color: 'bad',
message: "Build of <${env.BUILD_URL}|${env.JOB_BASE_NAME} #${env.BUILD_NUMBER}> is failed!"
)
}
}
}