[DO-1519] add_messenger_master_host (!74)

Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.tech>
Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/74
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
Co-authored-by: Rustam Tagaev <rustam.tagaev@avroid.team>
Co-committed-by: Rustam Tagaev <rustam.tagaev@avroid.team>
This commit is contained in:
Rustam Tagaev
2025-02-06 19:21:48 +03:00
committed by Denis Patrakeev
parent efa1586ef1
commit 05394bf9ff
2 changed files with 174 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
multibranchPipelineJob('Cloud/Apps-Frontend/cloud-messenger-host') {
description('cloud-messenger-host')
displayName('cloud-messenger-host')
factory {
remoteJenkinsFileWorkflowBranchProjectFactory {
localMarker('')
matchBranches(true)
fallbackBranch('master')
lookupInParameters(false)
remoteJenkinsFile('pipelines/Cloud/Apps-Frontend/cloud-messenger-host.groovy')
remoteJenkinsFileSCM {
gitSCM {
userRemoteConfigs {
userRemoteConfig {
url("${JENKINS_GIT_REPOSITORY_URL}/DevOps/jenkins-pipelines.git")
credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}")
name('')
refspec('')
}
}
gitTool('')
browser {}
}
}
}
}
branchSources {
branchSource {
source {
giteaSCMSource {
serverUrl("${JENKINS_GIT_REPOSITORY_URL}")
repoOwner('Apps-Frontend')
repository('cloud-messenger-host')
credentialsId("${JENKINS_GIT_CREDENTIALS_HTTP}")
id('Apps-Frontend/cloud-messenger-host')
traits {
giteaBranchDiscovery {
// 1 Exclude branches that are also filed as PRs
// 2 Only branches that are also filed as PRs
// 3 Only branches that are also filed as PRs or main
// 4 All branches
strategyId(1)
}
giteaPullRequestDiscovery {
// 1 Merging the pull request with the current target branch revision
// 2 The current pull request revision
// 3 Both the current pull request revision and the pull request merged with
// the current target branch revision
strategyId(2)
}
giteaForkDiscovery {
// 1 Merging the pull request with the current target branch revision
// 2 The current pull request revision
// 3 Both the current pull request revision and the pull request merged with
// the current target branch revision
strategyId(2)
trust {
giteaTrustContributors()
}
}
giteaTagDiscovery()
pruneStaleBranch()
pruneStaleTag()
refSpecs {
templates {
refSpecTemplate {
value('+refs/heads/*:refs/remotes/@{remote}/*')
}
}
}
}
}
}
}
}
orphanedItemStrategy {
discardOldItems {
numToKeep(20)
}
defaultOrphanedItemStrategy {
pruneDeadBranches(true)
numToKeepStr('10')
daysToKeepStr('10')
}
}
}

View File

@@ -0,0 +1,82 @@
@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/cloud-messenger-host.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/cloud-messenger-host:${imageTag}",
"-f Dockerfile ."
)
if (branch == publishBranch) {
maintainerUser = 'rishat.gabaidullov@avroid.team'
buildImage.push()
}
}
}
}
}
} 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
)
}
}
}
}