1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- @Library('jenkins-library-iru@master') _
- def Label = "analis-lab-update-${UUID.randomUUID().toString()}"
- pipeline {
- options {
- buildDiscarder logRotator(numToKeepStr: '10')
- disableConcurrentBuilds()
- timeout(time: 60, unit: 'MINUTES')
- }
- agent {
- kubernetes {
- label Label
- yaml libraryResource('deployPodDefinition.yaml')
- }
- }
- environment {
- CONTEXT='provision@sdsys.office'
- DOCKER_IMAGE='web-laboratory/analis'
- HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/labportal/k8s.git'
- JENKINS_MAIL='jenkins.dev@sdsys.ru'
- DOCKER_REGISTRY='images.sdsys.ru'
- HELM_REPO='https://images.sdsys.ru/artifactory/helm/'
- CHART_NAME=''
- CHART_PATH=''
- PROJECT=''
- HELM_DIR=''
- TAG=''
- }
- parameters {
- string(
- name: "mailto",
- defaultValue: "admin@sdsys.ru",
- description: "Email which has to be notified."
- )
- }
- stages {
- stage("Prepare to Update") {
- steps {
- script {
- echo "Pull Repo"
- gitOps.clone(HELM_GIT_URL)
- HELM_DIR = dirOps.calculateDir(HELM_GIT_URL)
- CHART_PATH = "helm/" + DOCKER_IMAGE.split("/")[1]
- VALUES_FILE = HELM_DIR + "/helm/" + "dev-" + DOCKER_IMAGE.split("/")[1] + ".yaml"
- }
- }
- }
- stage("Update Helm Chart values.yaml") {
- steps {
- script {
- echo "View ${VALUES_FILE}"
- sh "cat ${VALUES_FILE}"
- }
- }
- }
- stage("Update APP") {
- steps {
- script {
- RELEASENAME = DOCKER_IMAGE.split("/")[1]
- NAMESPACE = DOCKER_IMAGE.split("/")[1]
- try {
- echo "Update APP"
- k8sHelmOps.upgrade(CONTEXT, NAMESPACE, RELEASENAME, CHART_PATH, VALUES_FILE, HELM_REPO)
- echo "Update success!!!"
- }
- catch(err) {
- echo "Recovering APP"
- k8sHelmOps.rollback(CONTEXT, NAMESPACE, RELEASENAME)
- throw err
- }
- }
- }
- }
- // stage("Tagging Image") {
- // steps {
- // script {
- // echo "Tagging ${TAG} to latest"
- // IMAGE = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}"
- // k8sBuildImage.crane(IMAGE, TAG, 'latest')
- // }
- // }
- // }
- }
- 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}"
- }
- }
- }
|