@Library('shared-lib') _ import tech.avroid.kube.PodTemplates import tech.avroid.scm.Git import tech.avroid.jenkins.Notifications properties([ buildDiscarder(logRotator(daysToKeepStr: '10', numToKeepStr: '10')), disableConcurrentBuilds() ]) String repoPath = 'Apps-Frontend/web-cloud-messenger-dialogs.git' String maintainerUser = '' String appVersion = '' String publishBranch = 'develop' String imageTag = '' Map gitVars = [:] Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH) PodTemplates slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, ["${env.JENKINS_K8S_HARBOR_SECRET}"]) String branch = git.getBranch() slaveTemplates.jnlp { slaveTemplates.docker { slaveTemplates.nodejs(imageVersion='18.19-alpine3.18') { try { node(POD_LABEL){ stage('Download sources') { gitVars = git.clone([urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${repoPath}", branch: branch]) } container('nodejs'){ stage('build app'){ sh """#!/bin/sh npm config set registry ${env.JENKINS_NEXUS_NPM_REPOSITORY} npm install npm run build """ } } container('docker'){ stage('build and push image'){ appVersion = readJSON(file: 'package.json').version imageTag = "${appVersion}-${gitVars.GIT_COMMIT.take(5)}" docker.withRegistry("https://${env.JENKINS_DOCKER_REGISTRY}", env.JENKINS_HARBOR_CREDENTIALS) { Object buildImage = docker.build( "${env.JENKINS_DOCKER_REGISTRY}/cloud/web-cloud-messenger-dialogs:${imageTag}", "-f Dockerfile ." ) if (branch == publishBranch) { maintainerUser = 'rishat.gabaidullov@avroid.team' buildImage.push() stage('deploy application'){ build job: 'Cloud/Deploy/Frontend/web-cloud-messenger-dialogs-deploy', parameters: [ string(name: 'ENV', value: 'DEV'), string(name: 'APP_VERSION', value: imageTag) ], wait: false } } } } } } } catch(err) { errorMessage = err.getMessage() println 'ERROR: ' + errorMessage currentBuild.result = 'FAILURE' String emailSubject = "${currentBuild.currentResult}. Pipeline task: ${currentBuild.fullDisplayName}" Notifications.email( script: this, subject: emailSubject, errorString: errorMessage, recipientProviders: [], to: maintainerUser ) } } } }