forked from lunr-php/lunr.vortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
157 lines (147 loc) · 5.54 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!groovy
/*
* SPDX-FileCopyrightText: Copyright 2016 M2mobi B.V., Amsterdam, The Netherlands
* SPDX-FileCopyrightText: Copyright 2022 Move Agency Group B.V., Zwolle, The Netherlands
* SPDX-License-Identifier: CC0-1.0
*/
def ant_sh(String stage){
sh "/bin/ant ${stage}"
}
def deploy(){
if(env.deploy){
sh "salt-connect library project=lunr branch=master env=m2mobi"
}
}
def dependencies(String dependency_tool){
try {
sh "${dependency_tool} install"
} catch(error){
echo "WARNING: Couldn't setup dependencies!"
}
}
pipeline {
agent {
label "web"
}
stages {
stage('Checkout'){
steps{
checkout changelog: false, poll: false, scm:
[
$class: 'GitSCM',
branches: [[name: 'master']],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '../lunr-coding-standard']],
submoduleCfg: [],
userRemoteConfigs: [[url: 'https://github.com/lunr-php/lunr-coding-standard.git']]
]
checkout scm
}
}
stage('Clean'){
steps{
ant_sh('clean')
dependencies(env.dependency_tool)
ant_sh('pdepend')
}
post {
success {
publishHTML([
reportName: 'PDepend Reports',
reportDir: 'build/pdepend',
reportFiles: '',
alwaysLinkToLastBuild: true,
keepAll: true,
allowMissing: false
])
}
}
}
stage('Code inspection'){
steps{
parallel (
cpd: { ant_sh('phpcpd') },
cs: { ant_sh('phpcs') },
stan: { ant_sh('phpstan-ci') },
loc: { ant_sh('phploc') }
)
}
post {
always {
recordIssues enabledForFailure: true, tool: cpd(pattern: 'build/logs/pmd-cpd.xml')
recordIssues enabledForFailure: true, tool: phpStan(pattern: 'build/logs/phpstan.xml')
recordIssues enabledForFailure: true, tool: checkStyle(pattern: 'build/logs/checkstyle.xml'),
qualityGates: [[threshold: 999, type: 'TOTAL', unstable: true]]
}
}
}
stage('Unit tests'){
steps{
ant_sh('phpunit')
}
post {
success {
junit 'build/logs/junit.xml'
recordIssues enabledForFailure: true, tool: junitParser(pattern: 'build/logs/junit.xml')
step([
$class: 'CloverPublisher',
cloverReportDir: 'build/logs',
cloverReportFileName: 'clover.xml',
healthyTarget: [methodCoverage: 70, conditionalCoverage: 80, statementCoverage: 80],
unhealthyTarget: [methodCoverage: 50, conditionalCoverage: 60, statementCoverage: 60],
failingTarget: [methodCoverage: 30, conditionalCoverage: 40, statementCoverage: 40]
])
publishHTML([
reportName: 'Coverage Reports',
reportDir: 'build/coverage',
reportFiles: 'index.html',
alwaysLinkToLastBuild: true,
keepAll: true,
allowMissing: false
])
}
}
}
stage('SonarQube Analysis'){
when {
branch 'master'
}
environment {
ACCOUNT_KEY = null
PROJECT_SLUG = null
}
steps{
script {
ACCOUNT_KEY = GIT_URL.tokenize('/')[2]
PROJECT_SLUG_W_GIT = GIT_URL.tokenize('/')[3]
PROJECT_SLUG = PROJECT_SLUG_W_GIT.substring(0, PROJECT_SLUG_W_GIT.lastIndexOf('.'))
}
withSonarQubeEnv('M2mobi') {
sh """sonar-scanner \\
-Dsonar.projectKey=${ACCOUNT_KEY}:backend:${PROJECT_SLUG} \\
-Dsonar.projectName=Lunr.Vortex \\
-Dsonar.sources=src/ \\
-Dsonar.php.tests.reportPath=build/logs/junit.xml \\
-Dsonar.php.coverage.reportPaths=build/logs/clover.xml"""
sh "./tests/get-sonar-report.sh ${ACCOUNT_KEY}:backend:${PROJECT_SLUG}"
}
}
post {
always {
recordIssues enabledForFailure: true, tool: sonarQube(pattern: 'build/logs/sonar-report.json')
}
}
}
}
post {
success {
deploy()
}
failure {
emailext body: 'Please go to $BUILD_URL to see the result.',
recipientProviders: [[$class: 'RequesterRecipientProvider'], [$class: 'CulpritsRecipientProvider']],
subject: '$JOB_NAME ($JOB_BASE_NAME): Build $BUILD_DISPLAY_NAME: FAILED',
to: '${ENV,var="LUNR_MAILINGLIST"}'
}
}
}