-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
77 lines (64 loc) · 3 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
node('docker') {
ansiColor('xterm') {
stage('Checkout') {
checkout scm
}
stage('Pulling') {
sh 'docker pull jakzal/phpqa'
}
stage('Prepare directory') {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa chmod -R 777 build'
sh 'rm -rf build/logs'
sh 'mkdir -p build/logs'
}
stage('Install dependencies') {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa composer install --ignore-platform-reqs --no-scripts --no-progress --no-suggest'
}
stage('Run unit tests') {
sh 'cp phpunit.xml.dist phpunit.xml'
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa vendor/bin/simple-phpunit'
}
stage("Testing") {
parallel (
"PHPCodeSniffer": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpcs --warning-severity=0 --standard=PSR2 --encoding=UTF-8 --ignore="*.js" src/'
},
"PHPStan": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpstan analyse src/ || exit 0'
},
"PhpMetrics": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpmetrics --report-html=build/logs/phpmetrics.html src/ || exit 0'
publishHTMLReport('build/logs', 'phpmetrics.html', 'PHPMetrics')
},
"PHPMessDetector": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpmd src/ xml cleancode,codesize,unusedcode --reportfile build/logs/pmd.xml || exit 0'
replaceFilePath('build/logs/pmd.xml')
pmd canRunOnFailed: true, pattern: 'build/logs/pmd.xml'
},
"PHPMagicNumberDetector": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpmnd src/ --exclude=tests --progress --non-zero-exit-on-violation --ignore-strings=return,condition,switch_case,default_parameter,operation || exit 0'
},
"PHPCopyPasteDetector": {
sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa phpcpd --log-pmd build/logs/pmd-cpd.xml src/ || exit 0'
replaceFilePath('build/logs/pmd-cpd.xml')
dry canRunOnFailed: true, pattern: 'build/logs/pmd-cpd.xml'
}
)
}
}
}
def replaceFilePath(filePath) {
sh "sed -i 's#/project/#${workspace}/#g' ${filePath}"
}
def publishHTMLReport(reportDir, file, reportName) {
if (fileExists("${reportDir}/${file}")) {
publishHTML(target: [
allowMissing : true,
alwaysLinkToLastBuild: true,
keepAll : true,
reportDir : reportDir,
reportFiles : file,
reportName : reportName
])
}
}