123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- PROMO_SDK=[ service_name: 'info_promo-sdk', image: 'web-registration/promo-sdk', repo: 'git@github.com:icruportal/web-sdk-demo.git', dockerfile: 'Dockerfile-promo-sdk' ]
- PROMO_SEO=[ service_name: 'info_promo-seo', image: 'web-registration/promo-seo', repo: 'git@github.com:icruportal/web-registration.git', dockerfile: 'Dockerfile-promo-seo' ]
- @Library('jenkins-library-iru@master') _
- def Label = "web-registration-promo-build-${UUID.randomUUID().toString()}"
- pipeline {
- options {
- buildDiscarder logRotator(numToKeepStr: '10')
- disableConcurrentBuilds()
- timeout(time: 15, unit: 'MINUTES')
- }
- agent {
- kubernetes {
- label Label
- yaml libraryResource('promoPodDefinition.yaml')
- }
- }
- environment {
- CONTEXT='provision@sdsys.office'
- HELM_GIT_URL='ssh://git@git.sdsys.ru:8022/iru/k8s.git'
- HELM_REPO='https://images.sdsys.ru/artifactory/helm/'
- JENKINS_MAIL='jenkins.dev@sdsys.ru'
- DOCKER_REGISTRY='images.sdsys.ru'
- VALUES_FILE = ''
- SOURCE_DIR=''
- HELM_DIR=''
- TAG=''
- }
- parameters {
- choice (
- choices: 'promo-seo\npromo-sdk',
- description: 'Which repo to use?',
- name: 'APP_NAME'
- )
- string(
- name: "branch",
- defaultValue: "release",
- description: "Which branch to use"
- )
- string(
- name: "mailto",
- defaultValue: "admin@sdsys.ru",
- description: "Email which has to be notified."
- )
- }
- stages {
- stage("Calculate Variables") {
- steps {
- script {
- switch (APP_NAME) {
- case 'promo-sdk':
- SOURCE_GIT_URL = PROMO_SDK.repo
- DOCKER_IMAGE = PROMO_SDK.image
- SERVICE_NAME = PROMO_SDK.service_name
- DOCKER_FILE = PROMO_SDK.dockerfile
- BUILD_IMAGE_DIR = dirOps.calculateDir(SOURCE_GIT_URL)
- break
- case 'promo-seo':
- SOURCE_GIT_URL = PROMO_SEO.repo
- DOCKER_IMAGE = PROMO_SEO.image
- SERVICE_NAME = PROMO_SEO.service_name
- DOCKER_FILE = PROMO_SEO.dockerfile
- BUILD_IMAGE_DIR = dirOps.calculateDir(SOURCE_GIT_URL) + "/promo/build/libs"
- break
- }
- }
- }
- }
- stage("Prepare to build") {
- steps {
- script {
- echo "Pull ${SOURCE_GIT_URL}"
- gitOps.clone(SOURCE_GIT_URL)
- echo "CheckOut ${branch}"
- SOURCE_DIR = dirOps.calculateDir(SOURCE_GIT_URL)
- gitOps.checkout(SOURCE_DIR, branch)
- echo "Save Version"
- dir(SOURCE_DIR) {
- COMMIT = sh(script: 'echo $(git log -p -1 --pretty=format:"%h"|head -n1)', returnStdout: true).trim()
- }
- 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"
- }
- }
- }
- stage("Build APP") {
- steps {
- script {
- switch (APP_NAME) {
- case 'promo-sdk':
- echo "Build APP PROMO-SDK"
- dir("${SOURCE_DIR}") {
- buildOps.npmPromoSDK()
- }
- break
- case 'promo-seo':
- echo "Build APP PROMO-SEO"
- echo "Build customer-api"
- dir("${SOURCE_DIR}/customer-api") {
- buildOps.maven()
- }
- echo "Build public"
- dir("${SOURCE_DIR}/promo/src/public") {
- buildOps.npm()
- }
- echo "Build Promo"
- dir("${SOURCE_DIR}/promo") {
- buildOps.gradle()
- }
- }
- }
- }
- }
- stage("Build Image") {
- steps {
- script {
- IMAGE_TO_PUSH = "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${COMMIT}-${BUILD_NUMBER}"
- k8sBuildImage.kaniko(IMAGE_TO_PUSH,[CONTENT_DIR: BUILD_IMAGE_DIR],DOCKER_FILE)
- }
- }
- }
- stage("Update Helm Chart dev.yaml") {
- steps {
- script {
- TAG_PATH = "images." + DOCKER_IMAGE.split("/")[1].replace('-', '_')
- echo "Update ${TAG_PATH} to ${IMAGE_TO_PUSH} in ${VALUES_FILE}"
- gitOps.clone(HELM_GIT_URL)
- 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"
- k8sHelmOps.upgrade(CONTEXT, DOCKER_IMAGE.split("/")[0], DOCKER_IMAGE.split("/")[0], CHART_PATH, VALUES_FILE, HELM_REPO)
- }
- 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] + " to " + COMMIT
- 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}"
- }
- }
- }
|