Created
July 5, 2017 21:23
-
-
Save jamesj2/375e050ba9ee7ee4837c183635a9b924 to your computer and use it in GitHub Desktop.
Learning Jenkins Pipeline via trial and error. This is what I've come up with so far. The "tools" are PHP testing and metrics installed via composer stored in their own build/tools/composer.json. AWS ECR is used to store my docker images, you can use php/xxx from Docker HUB.
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
{ | |
"require": { | |
"phing/phing": "^2.16", | |
"phploc/phploc": "^4.0", | |
"pdepend/pdepend": "~2.5.0", | |
"sebastian/phpcpd": "^3.0", | |
"phpmd/phpmd": "2.6", | |
"squizlabs/php_codesniffer": "*", | |
"pear/http_request2": "^2.3", | |
"phpunit/phpunit": "6.1", | |
"phpunit/dbunit": "^3.0", | |
"theseer/phpdox": "^0.10.1", | |
"jakub-onderka/php-parallel-lint": "^0.9.2" | |
} | |
} |
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 | |
pipeline { | |
agent any | |
// triggers { | |
// cron('H 4/* 0 0 1-5') | |
// } | |
// tools { | |
// nodejs 'Node 6.x' | |
// } | |
parameters { | |
string(name: 'GIT_URL', defaultValue: 'https://github.com/xxx.git', description: 'URL to your repository') | |
string(name: 'GIT_CREDENTIALS', defaultValue: '', description: 'Credential ID for your repository') | |
string(name: 'GIT_BRANCH', defaultValue: 'master', description: 'Branch of your repository') | |
string(name: 'AWS_URL', defaultValue: 'https://xxx', description: 'URL of your AWS ECR repository, example: "https://__ACCOUNTID__.dkr.ecr.__REGION__.amazonaws.com"') | |
string(name: 'AWS_CREDENTIALS', defaultValue: 'ecr:xxx', description: 'Credential ID for your AWS repository, example: "ecr:REGION:CREDENTIALID""') | |
string(name: 'AWS_PHP_TAG', defaultValue: 'xxx', description: 'ECR repository tag for PHP cli') | |
string(name: 'TOOLS_BIN_PATH', defaultValue: 'build/tools/vendor/bin', description: 'Tools are stored in build/tools, this is the relative path to your app') | |
string(name: 'TOOLS_APP_PATH', defaultValue: './app', description: 'Tools are stored in build/tools, this is the relative path to your app') | |
} | |
environment { | |
ENVIRONMENT = "production" | |
NODE_ENV = "production" | |
COMPOSER_HOME = "${env.HUDSON_HOME}" | |
} | |
stages { | |
stage ('Checkout') { | |
steps { | |
git branch: "${params.GIT_BRANCH}", credentialsId: "${params.GIT_CREDENTIALS}", url: "${params.GIT_URL}" | |
} | |
} | |
stage('Build') { | |
steps { | |
/* Do your building stuff here, npm, gulp, composer, etc */ | |
script { | |
docker.image('composer:latest').inside{ | |
sh 'composer install -a --no-dev --ignore-platform-reqs --no-scripts --no-interaction --no-ansi --no-progress' | |
} | |
} | |
} | |
} | |
stage('Test'){ | |
steps { | |
// clean up directories | |
sh 'rm -rf build/api build/coverage build/logs build/pdepend build/phpdox' | |
sh 'mkdir build/api build/coverage build/logs build/pdepend build/phpdox' | |
script { | |
docker.withRegistry("${params.AWS_URL}", "${params.AWS_CREDENTIALS}") { | |
// Get build tools via composer | |
docker.image('composer:latest').inside{ | |
sh 'cd build/tools && composer install -a --ignore-platform-reqs --no-scripts --no-interaction --no-ansi --no-progress' | |
} | |
docker.image("${params.AWS_PHP_TAG}").inside{ | |
// PHP Lint | |
sh "${params.TOOLS_BIN_PATH}/parallel-lint --exclude vendor/ ${params.TOOLS_APP_PATH}" | |
// PHPUnit | |
sh "${params.TOOLS_BIN_PATH}/phpunit -c build/phpunit.xml || exit 0" | |
// PHP Codestyle | |
sh "${params.TOOLS_BIN_PATH}/phpcs --report=checkstyle --report-file=`pwd`/build/logs/checkstyle.xml --standard=Zend --extensions=php --ignore=autoload.php --ignore=vendor/ ./app || exit 0" | |
// Copy & Paste detection | |
sh "${params.TOOLS_BIN_PATH}/phpcpd --log-pmd build/logs/pmd-cpd.xml --exclude vendor ${params.TOOLS_APP_PATH} || exit 0" | |
// Mess detection | |
sh "${params.TOOLS_BIN_PATH}/phpmd . xml build/phpmd.xml --reportfile build/logs/pmd.xml --exclude vendor/ || exit 0" | |
} | |
} | |
} | |
// phpunit reporting | |
step([ | |
$class: 'XUnitBuilder', | |
thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']], | |
tools: [[$class: 'JUnitType', pattern: 'build/logs/junit.xml']] | |
]) | |
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'build/coverage', reportFiles: 'index.html', reportName: 'Coverage Report', reportTitles: '']) | |
// jenkins plugin not working with pipeline yet @see https://github.com/jenkinsci/cloverphp-plugin/pull/6 | |
//step([$class: 'CloverPHPPublisher',cloverXml: 'build/logs/clover.xml']) | |
// jenkins plugin not working with pipeline yet | |
//step([$class: 'Crap4JPublisher', reportPattern: 'build/logs/crap4j.xml', healthThreshold: '10']) | |
// checkstyle reporting | |
checkstyle pattern: 'build/logs/checkstyle.xml' | |
// Copy & Paste detection reporting | |
dry canRunOnFailed: true, pattern: 'build/logs/pmd-cpd.xml' | |
// Mess detection reporting | |
pmd canRunOnFailed: true, pattern: 'build/logs/pmd.xml' | |
} | |
} | |
stage('Documentation') { | |
steps { | |
script { | |
docker.withRegistry("${params.AWS_URL}", "${params.AWS_CREDENTIALS}") { | |
docker.image("${params.AWS_PHP_TAG}").inside{ | |
// LOC | |
sh "${params.TOOLS_BIN_PATH}/phploc --count-tests --exclude vendor/ --log-csv build/logs/phploc.csv --log-xml build/logs/phploc.xml ${params.TOOLS_APP_PATH}" | |
// PDepend | |
sh "${params.TOOLS_BIN_PATH}/pdepend --jdepend-xml=build/logs/jdepend.xml --jdepend-chart=build/pdepend/dependencies.svg --overview-pyramid=build/pdepend/overview-pyramid.svg --ignore=vendor --ignore=build ${params.TOOLS_APP_PATH}" | |
// PHPDox | |
sh "${params.TOOLS_BIN_PATH}/phpdox -f build/phpdox.xml" | |
} | |
} | |
} | |
} | |
} | |
stage('Deploy') { | |
steps { | |
echo 'Deploying' | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment