pipeline { agent { label "swarm" } options { disableConcurrentBuilds() timeout(time: 20, unit: 'MINUTES') } environment { DOCKER_IMAGE='lab/analis-wineservice' DOCKER_REGISTRY='registry.infoclinica.ru:5000' SWARM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/stack-deploy.git' SWARM_GIT_NAME='stack-deploy' JENKINS_MAIL='jenkins@sdsys.ru' NEWTAG='' REV_NUMBER='' } parameters { string( name: "REVNUM", defaultValue: "HEAD", description: "Revision number" ) string( name: "mailto", defaultValue: "admin@sdsys.ru", description: "Email which has to be notified." ) } stages { stage("SVN Checkout") { steps { sh """[ -d analis/.svn ] && svn cleanup analis svn co -r ${REVNUM} --force --no-auth-cache svn://192.168.21.250/programs/trunk/Services/Analis/Win32 analis --username public --password "sds#7753435" """ } } stage("Build") { steps { script { // Discover revision number REV_NUMBER=sh (script: "svn info --show-item last-changed-revision analis", returnStdout: true ).trim() echo "Last-Changed-Revision number is '$REV_NUMBER'" } sh "docker build -t ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ." sh "docker tag ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER} ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest" } } stage("Publish") { steps { sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER}" sh "docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest" } } stage("Tagging"){ steps{ withCredentials([sshUserPrivateKey(credentialsId: 'provision', keyFileVariable: 'GIT_SSH_KEY', passphraseVariable: '', usernameVariable: 'GIT_SSH_USERNAME')]) { sh """[ -d ${SWARM_GIT_NAME} ] && rm -rf ${SWARM_GIT_NAME} GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ git clone ${SWARM_GIT_URL} cd ${SWARM_GIT_NAME} echo -n ${REV_NUMBER}-${BUILD_NUMBER} > tags/${DOCKER_IMAGE}.build-version git add -A git config --global user.email "${JENKINS_MAIL}" git config --global user.name "Jenkins" git commit -m "Version update tags/lab/${DOCKER_IMAGE}.build-version = ${REV_NUMBER}-${BUILD_NUMBER}" GIT_SSH_COMMAND='ssh -i ${GIT_SSH_KEY} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ git push origin master cd .. rm -rf ${SWARM_GIT_NAME} ls""" } } } } post { failure { mail charset: 'UTF-8', subject: "Jenkins build ERROR", mimeType: 'text/html', to: "${mailto}", body: "ATTENTION!!! Jenkins job FAILED.\n\n
Project Name: ${env.JOB_NAME}\n
Build TAG: ${REV_NUMBER}-${BUILD_NUMBER}\n
Build URL: ${RUN_DISPLAY_URL}" } success { mail charset: 'UTF-8', subject: "Jenkins build SUSCCESS", mimeType: 'text/html', to: "${mailto}", body: "Congratulations!!! Jenkins job successfully finished\n\n
Project Name: ${env.JOB_NAME}\n
Build TAG: ${REV_NUMBER}-${BUILD_NUMBER}\n
Build URL: ${RUN_DISPLAY_URL}" } } }