Skip to content

Instantly share code, notes, and snippets.

@mllrjb
Created October 20, 2016 20:48
Show Gist options
  • Save mllrjb/7a7d5e3d9cfd94270d1e4807e93a84d4 to your computer and use it in GitHub Desktop.
Save mllrjb/7a7d5e3d9cfd94270d1e4807e93a84d4 to your computer and use it in GitHub Desktop.
Jenkinsfile-kitchen-sink
#!groovy
/**
* Requires tool definitions for nodejs, jdk, maven, and ant
* Requires config files .npmrc and maven-settings.xml
*/
node() {
// checkout clean code
stage("checkout") {
checkout scm
sh "git clean -fdx"
}
// setup tools and env
stage("setup" ) {
def nodejs = tool 'nodejs-6.x'
def java = tool 'jdk8'
def maven = tool 'maven-3.3'
def ant = tool 'ant-1.9'
env.JAVA_HOME = "${java}"
env.PATH="${java}/bin:${maven}/bin:${ant}/bin:${nodejs}/bin:${env.PATH}"
configFileProvider([configFile(fileId: '.npmrc', targetLocation: '.npmrc')]) {}
}
dir("app") {
// install dependencies
stage("install" ) {
sh "npm install"
}
// run tests
stage("test" ) {
def container;
try {
container = docker.image('postgres').run("-P -e POSTGRES_PASSWORD=changeit")
def port = container.port(5432).split(":")[1];
// container takes a few seconds to start up
retry(5) {
sleep 1
sh "db__port=${port} NODE_ENV=test npm run migrate"
}
sh "db__port=${port} npm test"
} finally {
if (container) {
container.stop();
}
}
}
// package code
stage("package") {
sh "npm run archive"
}
}
dir("installer") {
// build installer part
stage("build installer") {
configFileProvider([configFile(fileId: 'maven-settings.xml', variable: "MAVEN_SETTINGS")]) {
sh "mvn -s ${MAVEN_SETTINGS} install"
}
}
stage("archive") {
archiveArtifacts artifacts: "target/**/*.zip,target/**/*.md5"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment