[DO-1521] add_messenger_users_build (!81)

Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech>
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/81
Reviewed-by: Vasiliy Chipizhin <vasiliy.chipizhin@avroid.team>
This commit is contained in:
Rustam Tagaev
2025-02-12 11:54:08 +03:00
parent e8cdb91564
commit f2c1c3f614
4 changed files with 399 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
@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)}"
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
)
}
}
}
}