Update the Jenkinsfile to be a bit more modern and properly skip deployment in pull requests

This commit is contained in:
R. Tyler Croy 2016-11-09 11:46:25 -08:00
parent 79c90e0073
commit 23b3a24ccf
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
1 changed files with 29 additions and 25 deletions

54
Jenkinsfile vendored
View File

@ -1,35 +1,39 @@
#!groovy
#!/usr/bin/env groovy
def imageName = 'jenkinsciinfra/account-app'
/* Only keep the X most recent builds. */
properties([[$class: 'jenkins.model.BuildDiscarderProperty',
strategy: [$class: 'LogRotator',
numToKeepStr: '50',
artifactNumToKeepStr: '20']]])
numToKeepStr: '10',
artifactNumToKeepStr: '10']]])
stage 'Build'
node('docker') {
checkout scm
docker.image('java:8').inside {
sh './gradlew --no-daemon --info war'
step([$class: 'ArtifactArchiver',
artifacts: 'build/libs/*.war',
fingerprint: true])
stage('Build') {
timestamps {
checkout scm
docker.image('java:8').inside {
sh './gradlew --no-daemon --info war'
archiveArtifacts artifacts: 'build/libs/*.war', fingerprint: true
}
}
}
def container
stage('Prepare Container') {
timestamps {
sh 'git rev-parse HEAD > GIT_COMMIT'
shortCommit = readFile('GIT_COMMIT').take(6)
def imageTag = "${env.BUILD_ID}-build${shortCommit}"
echo "Creating the container ${imageName}:${imageTag}"
container = docker.build("${imageName}:${imageTag}")
}
}
/* Assuming we're not inside of a pull request or multibranch pipeline */
if (!(env.CHANGE_ID || env.BRANCH_NAME)) {
stage('Publish container') {
timestamps { container.push() }
}
}
}
node('docker') {
stage 'Package'
unarchive mapping: ['build/' : 'build/']
sh 'git rev-parse HEAD > GIT_COMMIT'
shortCommit = readFile('GIT_COMMIT').take(6)
def imageTag = "build${shortCommit}"
echo "Creating the container ${imageName}:${imageTag}"
def whale = docker.build("${imageName}:${imageTag}")
stage 'Deploy'
echo "Shipping ${imageTag}"
whale.push()
}