nginx-proxy-manager/Jenkinsfile

83 lines
2.6 KiB
Plaintext
Raw Normal View History

2018-05-03 15:43:04 +10:00
pipeline {
options {
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10'))
disableConcurrentBuilds()
}
agent any
environment {
2018-05-03 16:07:34 +10:00
IMAGE_NAME = "nginx-proxy-manager"
TEMP_IMAGE_NAME = "nginx-proxy-manager-build_${BUILD_NUMBER}"
2018-05-03 16:10:36 +10:00
TAG_VERSION = getPackageVersion()
2018-05-03 16:07:34 +10:00
}
2018-05-03 15:43:04 +10:00
stages {
stage('Prepare') {
steps {
2018-05-03 17:03:34 +10:00
sh '''docker pull jc21/nginx-proxy-manager-base
2018-05-03 15:43:04 +10:00
docker pull ${DOCKER_CI_TOOLS}'''
sh '''CWD=`pwd`
docker run --rm \\
-v $CWD/manager:/srv/manager \\
-w /srv/manager \\
2018-05-03 17:03:34 +10:00
jc21/nginx-proxy-manager-base \\
2018-05-03 15:43:04 +10:00
npm --registry=$NPM_REGISTRY install
exit $?'''
sh '''CWD=`pwd`
2018-05-03 17:03:34 +10:00
docker run --rm -v $CWD/manager:/srv/manager -w /srv/manager jc21/nginx-proxy-manager-base gulp build
2018-05-03 15:43:04 +10:00
exit $?'''
sh '''CWD=`pwd`
2018-05-03 17:03:34 +10:00
docker run --rm -e NODE_ENV=production -v $CWD/manager:/srv/manager -w /srv/manager jc21/nginx-proxy-manager-base npm prune --production
2018-05-03 15:43:04 +10:00
exit $?'''
sh '''docker run --rm \\
2018-05-03 16:57:10 +10:00
-v $(pwd)/manager:/data \\
2018-05-03 15:43:04 +10:00
${DOCKER_CI_TOOLS} \\
2018-05-03 16:00:29 +10:00
node-prune'''
2018-05-03 15:43:04 +10:00
}
}
stage('Build') {
2018-05-03 16:07:34 +10:00
steps {
2018-05-03 23:46:03 +10:00
sh 'docker build -t $TEMP_IMAGE_NAME .'
2018-05-03 15:43:04 +10:00
}
}
stage('Publish') {
2018-05-03 23:46:03 +10:00
when {
branch 'master'
}
2018-05-03 15:43:04 +10:00
steps {
2018-05-03 23:46:03 +10:00
sh 'docker tag $TEMP_IMAGE_NAME ${DOCKER_PRIVATE_REGISTRY}/$IMAGE_NAME:latest'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/$IMAGE_NAME:latest'
sh 'docker tag $TEMP_IMAGE_NAME ${DOCKER_PRIVATE_REGISTRY}/$IMAGE_NAME:$TAG_VERSION'
sh 'docker push ${DOCKER_PRIVATE_REGISTRY}/$IMAGE_NAME:$TAG_VERSION'
2018-05-04 00:05:29 +10:00
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:latest'
sh 'docker tag $TEMP_IMAGE_NAME docker.io/jc21/$IMAGE_NAME:$TAG_VERSION'
2018-05-03 15:43:04 +10:00
2018-05-03 23:46:03 +10:00
withDockerRegistry([credentialsId: 'jc21-dockerhub', url: '']) {
2018-05-04 00:05:29 +10:00
sh 'docker push docker.io/jc21/$IMAGE_NAME:latest'
sh 'docker push docker.io/jc21/$IMAGE_NAME:$TAG_VERSION'
2018-05-03 23:46:03 +10:00
}
2018-05-03 15:43:04 +10:00
2018-05-03 23:46:03 +10:00
sh 'docker rmi $TEMP_IMAGE_NAME'
2018-05-03 15:43:04 +10:00
}
}
}
triggers {
bitbucketPush()
}
post {
success {
slackSend color: "#72c900", message: "SUCCESS: <${BUILD_URL}|${JOB_NAME}> build #${BUILD_NUMBER} - Duration: ${currentBuild.durationString}"
}
failure {
slackSend color: "#d61111", message: "FAILED: <${BUILD_URL}|${JOB_NAME}> build #${BUILD_NUMBER} - Duration: ${currentBuild.durationString}"
}
}
}
2018-05-03 15:56:35 +10:00
def getPackageVersion() {
ver = sh(script: 'docker run --rm -v $(pwd)/manager:/data $DOCKER_CI_TOOLS bash -c "cat /data/package.json|jq -r \'.version\'"', returnStdout: true)
return ver.trim()
}