Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech> Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/96 Reviewed-by: Vasiliy Chipizhin <vasiliy.chipizhin@avroid.team> Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
92 lines
2.9 KiB
Groovy
92 lines
2.9 KiB
Groovy
@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-users.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)}"
|
|
currentBuild.description = imageTag
|
|
docker.withRegistry("https://${env.JENKINS_DOCKER_REGISTRY}", env.JENKINS_HARBOR_CREDENTIALS) {
|
|
|
|
Object buildImage = docker.build(
|
|
"${env.JENKINS_DOCKER_REGISTRY}/cloud/web-cloud-messenger-users:${imageTag}",
|
|
"-f Dockerfile ."
|
|
)
|
|
|
|
if (branch == publishBranch) {
|
|
maintainerUser = 'rishat.gabaidullov@avroid.team'
|
|
buildImage.push()
|
|
|
|
stage('deploy application'){
|
|
build job: 'Cloud/Deploy/Frontend/web-cloud-messenger-users-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
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|