Created
January 23, 2018 07:28
-
-
Save jhryniuk/18d919a2c881f184e5b60810996a1c9d to your computer and use it in GitHub Desktop.
Jenkinsfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String path = 'src/' | |
| node('docker') { | |
| ansiColor('xterm') { | |
| stage('Checkout') { | |
| checkout scm | |
| } | |
| stage('Pulling') { | |
| sh 'docker pull jakzal/phpqa' | |
| } | |
| stage('Prepare directory') { | |
| sh 'rm -rf build/logs' | |
| sh 'mkdir -p build/logs' | |
| } | |
| stage('Install dependencies') { | |
| sh 'composer install --ignore-platform-reqs --no-scripts --no-progress --no-suggest' | |
| } | |
| stage("Testing") { | |
| parallel ( | |
| "PHPCodeSniffer": { | |
| dockerRunTest('phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=PSR2 --encoding=UTF-8 --ignore="*.js" ' + path + ' || exit 0') | |
| replaceFilePath('build/logs/checkstyle.xml') | |
| checkstyle pattern: 'build/logs/checkstyle.xml' | |
| }, | |
| "PHPStan": { | |
| dockerRunTest('phpstan analyse ' + path + ' || exit 0') | |
| }, | |
| "PhpMetrics": { | |
| dockerRunTest('phpmetrics --report-html=build/logs/phpmetrics.html ' + path + ' || exit 0') | |
| publishHTMLReport('build/logs', 'phpmetrics.html', 'PHPMetrics') | |
| }, | |
| "PHPMessDetector": { | |
| dockerRunTest('phpmd ' + path + ' 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": { | |
| dockerRunTest('phpmnd ' + path + ' --exclude=tests --progress --non-zero-exit-on-violation --ignore-strings=return,condition,switch_case,default_parameter,operation || exit 0') | |
| }, | |
| "PHPCopyPasteDetector": { | |
| dockerRunTest('phpcpd --log-pmd build/logs/pmd-cpd.xml ' + path + ' || 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 | |
| ]) | |
| } | |
| } | |
| def dockerRunTest(attribute) { | |
| sh 'docker run --rm -v $(pwd):/project -w /project jakzal/phpqa ' + attribute | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment