123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- @Library('jenkins-library-iru@master') _
- def Label = "web-laboratory-node-build-${UUID.randomUUID().toString()}"
- pipeline {
- options {
- buildDiscarder logRotator(numToKeepStr: '10')
- disableConcurrentBuilds()
- timeout(time: 10, unit: 'MINUTES')
- }
- agent {
- kubernetes {
- label Label
- yaml libraryResource('standartPodDefinition.yaml')
- }
- }
- environment {
- CONTEXT='provision@sdsys.office'
- DOCKER_IMAGE='web-laboratory/node'
- HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git'
- HELM_REPO='https://images.sdsys.ru/artifactory/helm/'
- APP_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/node.git'
- JENKINS_MAIL='jenkins.dev@sdsys.ru'
- DOCKER_REGISTRY='images.sdsys.ru'
- CHART_PATH=''
- HELM_DIR=''
- IMAGE_TO_PUSH=''
- VALUES_FILE = ''
- }
- parameters {
- string(
- name: "repo",
- defaultValue: "prod",
- description: "Repository to build and/or deploy from."
- )
- string(
- name: "version",
- defaultValue: "16.1",
- description: "Witch version to build and/or deploy."
- )
- string(
- name: "mailto",
- defaultValue: "admin@sdsys.ru",
- description: "Email which has to be notified."
- )
- }
- stages {
- stage("Prepare to Build") {
- steps {
- script {
- echo "GIT clone ${HELM_GIT_URL}"
- gitOps.clone(HELM_GIT_URL)
- echo "Defining variables"
- HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
- CHART_PATH = "helm/" + DOCKER_IMAGE.split("/")[0]
- VALUES_FILE = HELM_DIR + "/helm/" + "dev-" + DOCKER_IMAGE.split("/")[0] + ".yaml"
- IMAGE_TO_PUSH = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${repo}-${BUILD_NUMBER}"
- }
- }
- }
- stage("Build Image") {
- steps {
- script {
- echo "Building ${IMAGE_TO_PUSH} with Kaniko"
- ARGS = [ "repo=${repo}" ]
- k8sBuildImage.kaniko(IMAGE_TO_PUSH, ARGS)
- }
- }
- }
- stage("Update Helm Chart values.yaml") {
- steps {
- script {
- TAG_PATH = "images." + DOCKER_IMAGE.split("/")[1]
- echo "Update ${TAG_PATH} to ${IMAGE_TO_PUSH} in ${VALUES_FILE}"
- def data = readYaml file: "${VALUES_FILE}"
- yamlOps.updateBuilder(TAG_PATH, data, IMAGE_TO_PUSH)
- writeYaml file: "${VALUES_FILE}", data: data, overwrite: true
- }
- }
- }
- stage("Update APP") {
- steps {
- script {
- try {
- echo "Update APP to ${IMAGE_TO_PUSH}"
- k8sHelmOps.upgrade(CONTEXT, DOCKER_IMAGE.split("/")[0], DOCKER_IMAGE.split("/")[0], CHART_PATH, VALUES_FILE, HELM_REPO)
- echo "Update success!!!"
- }
- catch(err) {
- echo "Recovering APP"
- k8sHelmOps.rollback(CONTEXT, DOCKER_IMAGE.split("/")[0], DOCKER_IMAGE.split("/")[0])
- throw err
- }
- }
- }
- }
- stage("Push changes to REPO") {
- steps {
- script {
- echo "Push changes to Repo"
- COMMIT = "Version update " + DOCKER_IMAGE.split("/")[1]
- gitOps.push(HELM_DIR, COMMIT)
- }
- }
- }
- }
- post {
- failure {
- mail charset: 'UTF-8',
- subject: "Jenkins build ERROR",
- mimeType: 'text/html',
- to: "${mailto}",
- body: "<b>ATTENTION!!!</b> <b><br> Jenkins job failed.\n\n <b><br>Project Name:</b> ${env.JOB_NAME} <b><br>\nBuild Number:</b> ${env.BUILD_NUMBER} <b><br>\nURL Build:</b> ${RUN_DISPLAY_URL}"
- }
- }
- }
|