#!/usr/bin/env groovy pipeline { agent any options { disableConcurrentBuilds() } environment { PROJECT_NAME = 'mylogger' STACK_NAME = "${env.PROJECT_NAME}-${env.BRANCH_NAME}" IMAGE = 'registry.verdnatura.es/mylogger' } stages { stage('Build') { when {branch 'master'} steps { script { def packageJson = readJSON file: 'package.json' env.VERSION = packageJson.version } sh 'docker-compose build --build-arg BUILD_ID=$BUILD_ID --parallel' sh 'docker tag $IMAGE:$VERSION $IMAGE:latest' } } stage('Push') { when {branch 'master'} environment { CREDENTIALS = credentials('docker-registry') } steps { script { def packageJson = readJSON file: 'package.json' env.VERSION = packageJson.version } sh 'docker login --username $CREDENTIALS_USR --password $CREDENTIALS_PSW $REGISTRY' sh 'docker-compose push' sh 'docker push $IMAGE:latest' } } } post { unsuccessful { setEnv() sendEmail() } } }