pipeline { agent any options { timeout(time: 30, unit: 'MINUTES') disableConcurrentBuilds abortPrevious: true } triggers { cron(env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'develop' ? '0 9 * * *' : '') } environment { REGISTRY_ADDRESS = "gitea.atria-soft.org" REGISTRY_ADDRESS_FULL = "https://${REGISTRY_ADDRESS}" REPOSITORY_BASE_NAME = 'kangaroo-and-rabbit/docker-builder' TAG_DOCKER = getEnvName(env.BRANCH_NAME) DOCKER_IMAGE_NAME_AND_TAG = "kangaroo-and-rabbit/archlinux-builder:${TAG_DOCKER}" } stages { stage('save-evironment') { steps { sh 'ls -la' sh 'pwd' sh 'uname -a' sh 'printenv | sort' sh 'git log -n 20' sh 'javac --version' } } stage('(prod) Build') { steps { sh 'docker build -t ${DOCKER_IMAGE_NAME_AND_TAG} .' } } stage('(prod) Push on registry') { when { expression { return env.TAG_DOCKER != 'other'; } } steps { script { docker.withRegistry(env.REGISTRY_ADDRESS_FULL, 'jenkins_auth_registry') { docker.image(env.DOCKER_IMAGE_NAME_AND_TAG).push(); } } } } } } def getEnvName(branchName) { if("master".equals(branchName)) { return "latest"; } else if("dev".equals(branchName)) { return "dev"; } return "other"; }