nginx-proxy-manager-zh/Jenkinsfile

72 lines
2.3 KiB
Plaintext
Raw Normal View History

2018-05-03 01:43:04 -04:00
pipeline {
options {
2018-06-19 19:53:18 -04:00
buildDiscarder(logRotator(numToKeepStr: '10'))
2018-05-03 01:43:04 -04:00
disableConcurrentBuilds()
}
agent any
environment {
2018-05-03 02:07:34 -04:00
IMAGE_NAME = "nginx-proxy-manager"
TEMP_IMAGE_NAME = "nginx-proxy-manager-build_${BUILD_NUMBER}"
2018-05-03 02:10:36 -04:00
TAG_VERSION = getPackageVersion()
2018-05-03 02:07:34 -04:00
}
2018-05-03 01:43:04 -04:00
stages {
stage('Prepare') {
steps {
2018-05-03 21:41:50 -04:00
sh 'docker pull jc21/$IMAGE_NAME-base'
2018-06-19 19:53:18 -04:00
sh 'docker pull jc21/node'
2018-05-03 21:38:52 -04:00
sh 'docker pull $DOCKER_CI_TOOLS'
2018-05-03 01:43:04 -04:00
}
}
stage('Build') {
2018-05-03 02:07:34 -04:00
steps {
2018-06-19 19:53:18 -04:00
sh 'docker run --rm -v $(pwd):/srv/app -w /srv/app jc21/node yarn --registry=$NPM_REGISTRY install'
sh 'docker run --rm -v $(pwd):/srv/app -w /srv/app jc21/node bin/build'
2018-05-03 21:38:52 -04:00
sh 'rm -rf node_modules'
2018-06-19 19:53:18 -04:00
sh 'docker run --rm -v $(pwd):/srv/app -w /srv/app jc21/node yarn --registry=$NPM_REGISTRY install --prod'
sh 'docker run --rm -v $(pwd):/data $DOCKER_CI_TOOLS node-prune'
2018-05-07 20:37:26 -04:00
sh 'docker build --squash --compress -t $TEMP_IMAGE_NAME .'
2018-05-03 01:43:04 -04:00
}
}
stage('Publish') {
2018-05-03 09:46:03 -04:00
when {
branch 'master'
}
2018-05-03 01:43:04 -04:00
steps {
2018-05-03 09:46:03 -04: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-03 10:05:29 -04: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 01:43:04 -04:00
2018-05-03 10:13:36 -04:00
withCredentials([usernamePassword(credentialsId: 'jc21-dockerhub', passwordVariable: 'dpass', usernameVariable: 'duser')]) {
sh "docker login -u '${duser}' -p '$dpass'"
2018-05-03 10:05:29 -04:00
sh 'docker push docker.io/jc21/$IMAGE_NAME:latest'
sh 'docker push docker.io/jc21/$IMAGE_NAME:$TAG_VERSION'
2018-05-03 09:46:03 -04:00
}
2018-05-03 01:43:04 -04:00
}
}
}
triggers {
bitbucketPush()
}
post {
success {
2018-06-19 19:53:18 -04:00
juxtapose event: 'success'
2018-05-17 19:33:41 -04:00
sh 'figlet "SUCCESS"'
2018-05-03 01:43:04 -04:00
}
failure {
2018-06-19 19:53:18 -04:00
juxtapose event: 'failure'
2018-05-17 19:33:41 -04:00
sh 'figlet "FAILURE"'
2018-05-03 01:43:04 -04:00
}
2018-05-03 21:38:52 -04:00
always {
sh 'docker rmi $TEMP_IMAGE_NAME'
}
2018-05-03 01:43:04 -04:00
}
}
2018-05-03 01:56:35 -04:00
def getPackageVersion() {
2018-06-19 19:53:18 -04:00
ver = sh(script: 'docker run --rm -v $(pwd):/data $DOCKER_CI_TOOLS bash -c "cat /data/package.json|jq -r \'.version\'"', returnStdout: true)
2018-05-03 01:56:35 -04:00
return ver.trim()
}