docker-1/Jenkinsfile

74 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env groovy
properties([
2017-11-06 13:22:21 +00:00
buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '5')),
2017-11-08 10:45:39 +00:00
pipelineTriggers([cron('H H/6 * * *')]),
])
2018-02-05 17:38:02 +00:00
timeout(20) {
2016-03-15 18:16:56 +00:00
node('docker') {
deleteDir()
stage('Checkout') {
checkout scm
}
2017-02-06 10:56:03 +00:00
if (!infra.isTrusted()) {
stage('shellcheck') {
// newer versions of the image don't have cat installed and docker pipeline fails
docker.image('koalaman/shellcheck:v0.4.6').inside() {
// run shellcheck ignoring error SC1091
// Not following: /usr/local/bin/jenkins-support was not specified as input
sh "shellcheck -e SC1091 *.sh"
}
}
2017-02-06 10:56:03 +00:00
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
2017-02-06 10:56:03 +00:00
*/
stage('Build') {
docker.build('jenkins')
2017-07-20 17:19:03 +00:00
docker.build('jenkins:alpine', '--file Dockerfile-alpine .')
2017-02-06 10:56:03 +00:00
}
2017-02-06 10:56:03 +00:00
stage('Test') {
sh """
git submodule update --init --recursive
git clone https://github.com/sstephenson/bats.git
"""
}
2017-09-21 12:25:02 +00:00
def labels = ['debian', 'slim', 'alpine']
2017-09-21 12:25:02 +00:00
def builders = [:]
for (x in labels) {
def label = x
// Create a map to pass in to the 'parallel' step so we can fire all the builds at once
builders[label] = {
stage("Test ${label}") {
def dockerfile = label == 'debian' ? 'Dockerfile' : "Dockerfile-${label}"
sh "DOCKERFILE=${dockerfile} bats/bin/bats tests"
}
}
}
2017-09-21 12:25:02 +00:00
parallel builders
2017-02-06 10:56:03 +00:00
} else {
/* In our trusted.ci environment we only want to be publishing our
* containers from artifacts
*/
stage('Publish') {
infra.withDockerCredentials {
sh './publish.sh'
2017-07-20 17:12:20 +00:00
sh './publish.sh --variant alpine'
sh './publish.sh --variant slim'
}
}
}
2016-03-15 18:16:56 +00:00
}
2018-02-05 17:38:02 +00:00
}