-
-
Save NoodlesNZ/bf9b50cab82093097796d354e37083f0 to your computer and use it in GitHub Desktop.
Jenkinsfile example
This file contains 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
#!groovy | |
caughtError = 0 | |
try { | |
node { | |
stage('Checkout') { | |
checkout scm | |
sh 'rm -rf build/{logs,pdepend}' | |
sh 'mkdir -p build/{logs,pdepend}' | |
sh '/usr/local/bin/composer install' | |
} | |
stage('Code analysis') { | |
parallel ( | |
phpmd: { | |
sh '/usr/bin/phpmd public_html xml build/phpmd.xml --reportfile build/logs/pmd.xml --suffixes php --ignore-violations-on-exit' | |
}, | |
phpcs: { | |
sh '/usr/bin/phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=build/phpcs.xml --extensions=php --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 public_html tests' | |
}, | |
phploc: { | |
sh '/usr/bin/phploc --count-tests --log-csv build/logs/phploc.csv --log-xml build/logs/phploc.xml public_html tests' | |
}, | |
) | |
} | |
stage('Unit tests') { | |
sh './vendor/phpunit/phpunit/phpunit --configuration phpunit-no-coverage-unit-only.xml --no-coverage --log-junit build/logs/junit.xml' | |
} | |
stage('Publishing Report') { | |
parallel ( | |
phpmd: { | |
step( | |
[ | |
$class: 'PmdPublisher', | |
canComputeNew: false, | |
defaultEncoding: '', | |
pattern: 'build/logs/pmd.xml', | |
healthy: '70', | |
unHealthy: '999' | |
] | |
) | |
}, | |
phpcs: { | |
step( | |
[ | |
$class: 'CheckStylePublisher', | |
canComputeNew: false, | |
defaultEncoding: '', | |
healthy: '100', | |
pattern: 'build/logs/checkstyle.xml', | |
unHealthy: '999' | |
] | |
) | |
}, | |
phpunit: { | |
step( | |
[ | |
$class: 'XUnitBuilder', | |
testTimeMargin: '3000', | |
thresholdMode: 1, | |
thresholds: [[ | |
$class: 'FailedThreshold', | |
failureNewThreshold: '', | |
failureThreshold: '', | |
unstableNewThreshold: '', | |
unstableThreshold: '' | |
], | |
[ | |
$class: 'SkippedThreshold', | |
failureNewThreshold: '', | |
failureThreshold: '', | |
unstableNewThreshold: '', | |
unstableThreshold: '' | |
]], | |
tools: [[ | |
$class: 'PHPUnitJunitHudsonTestType', | |
deleteOutputFiles: true, | |
failIfNotNew: true, | |
pattern: 'build/logs/junit.xml', | |
skipNoTestFiles: false, | |
stopProcessingIfError: true | |
]] | |
] | |
) | |
} | |
) | |
} | |
// If we got here, it means the build was a success. | |
currentBuild.result = "SUCCESS" | |
} | |
} | |
catch(caughtError) { | |
currentBuild.result = "FAILURE" | |
caughtError = caughtError | |
} | |
finally { | |
node { | |
if (currentBuild.result == "SUCCESS") { | |
slackSend(channel: '#bottest', color: 'good', message: "Build succeeded - (<${env.BUILD_URL}|Open>)") | |
} | |
else { | |
slackSend(channel: '#bottest', color: 'bad', message: "Build failed - (<${env.BUILD_URL}|Open>)") | |
} | |
if (caughtError != 0) { | |
throw caughtError | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment