@Library('jenkins-library-iru@master') _ def Label = "analis-lab-build-${UUID.randomUUID().toString()}" pipeline { options { buildDiscarder logRotator(numToKeepStr: '10') disableConcurrentBuilds() timeout(time: 15, unit: 'MINUTES') } agent { kubernetes { label Label yaml libraryResource('analisBuildPodDefinition.yaml') } } environment { CONTEXT='provision@sdsys.office' JENKINS_MAIL='jenkins.dev@sdsys.ru' DOCKER_REGISTRY='images.sdsys.ru' DOCKER_IMAGE='web-laboratory/analis' REPO='svn://192.168.21.250/programs/trunk/Services/Analis/Win32' HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git' TAG='' SVN_DIR='analis' REV_NUMBER='' CHART_PATH='' HELM_DIR='' IMAGE_TO_PUSH='' VALUES_FILE ='' } 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 { script { svnOps.checkout(REPO, REPO.split("/")[-2].toLowerCase(), REVNUM) REV_NUMBER = svnOps.revNumber(REPO.split("/")[-2].toLowerCase()) echo "REV_NUMBER = ${REV_NUMBER}" gitOps.clone(HELM_GIT_URL) HELM_DIR = dirOps.calculateDir(HELM_GIT_URL) CHART_PATH = "helm/" + DOCKER_IMAGE.split("/")[0] VALUES_FILE = HELM_DIR + "/helm/" + "dev-" + DOCKER_IMAGE.split("/")[1] + ".yaml" IMAGE_TO_PUSH = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${REV_NUMBER}-${BUILD_NUMBER}" } } } stage("Build Image") { steps { script { echo "Building ${IMAGE_TO_PUSH} with Kaniko" k8sBuildImage.kaniko(IMAGE_TO_PUSH) TAG = '${REV_NUMBER}-${BUILD_NUMBER}' echo "Taging ${IMAGE_TO_PUSH} to latest" k8sBuildImage.crane(IMAGE_TO_PUSH) } } } stage("Update Helm Chart values.yaml") { steps { script { echo "Update Helm Chart" def data = readYaml file: "${VALUES_FILE}" TAG = "${REV_NUMBER}-${BUILD_NUMBER}" TAG_PATH = "images." + DOCKER_IMAGE.split("/")[1] + ".build" echo "Update ${TAG_PATH} to ${TAG} in ${VALUES_FILE}" yamlOps.updateBuilder(TAG_PATH, data, TAG) writeYaml file: "${VALUES_FILE}", data: data, overwrite: true } } } stage("Push changes to REPO") { steps { script { echo "Push changes to Repo" COMMIT = "Build version ${TAG}" gitOps.push(HELM_DIR, COMMIT) } } } } 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}
\nBuild Number:
${env.BUILD_NUMBER}
\nURL Build:
${RUN_DISPLAY_URL}" } } }