@Library('jenkins-library@master') _
def Label = "node-iru-build-${UUID.randomUUID().toString()}"
pipeline {
options {
buildDiscarder logRotator(numToKeepStr: '10')
disableConcurrentBuilds()
timeout(time: 10, unit: 'MINUTES')
}
agent {
kubernetes {
label Label
yaml libraryResource('adminPodDefinition.yaml')
}
}
environment {
CLOUD='cloud-it-k8s'
DOCKER_IMAGE='iru/node'
CHART_SUBPATH='helm/info'
NAMESPACE='info'
HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
APP_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/node.git'
JENKINS_MAIL='jenkins.dev@sdsys.ru'
DOCKER_REGISTRY='jcr.infoclinica.ru'
PROJECT=''
CHART_NAME=''
CHART_PATH=''
HELM_DIR=''
TAG=''
}
parameters {
string(
name: "repo",
defaultValue: "prod",
description: "Repository to build and/or deploy from."
)
string(
name: "mailto",
defaultValue: "admin@sdsys.ru",
description: "Email which has to be notified."
)
}
stages {
stage("Prepare to Build") {
steps {
script {
gitOps.clone(HELM_GIT_URL)
HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
CHART_PATH = "${HELM_DIR}/${CHART_SUBPATH}"
PROJECT = DOCKER_IMAGE.split("/")[1]
}
}
}
stage("Build Image") {
steps {
script {
echo "Build Image with Kaniko"
REGISTRY = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
ARGS = [ "repo=${repo}", "version=${version}" ]
TAG = "${repo}-${BUILD_NUMBER}"
k8sBuildImage.kaniko(REGISTRY, TAG, ARGS)
}
}
}
stage("Update Helm Chart values.yaml") {
steps {
script {
echo "Update Helm Chart"
def data = readYaml file: "${CHART_PATH}/values.yaml"
TAG_PATH = "images.${PROJECT}.dev"
yamlOps.updateBuilder(TAG_PATH, data, TAG)
writeYaml file: "${CHART_PATH}/values.yaml", data: data, overwrite: true
}
}
}
// stage("Update APP") {
// steps {
// script {
// RELEASENAME = CHART_SUBPATH.split("/")[1]
// try {
// echo "Update APP"
// k8sHelmOps.upgrade(CLOUD, NAMESPACE, RELEASENAME, CHART_PATH)
// }
// catch(err) {
// echo "Recovering APP"
// k8sHelmOps.rollback(CLOUD, NAMESPACE, RELEASENAME)
// throw err
// }
// }
// }
// }
// stage("Push changes to REPO") {
// steps {
// script {
// echo "Push changes to Repo"
// COMMIT = "Version update ${PROJECT}"
// 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}"
// }
// }
}