From e968d6bbdbd9a63079695a17d04d70577f707f7c Mon Sep 17 00:00:00 2001 From: Dmitrij Prokov Date: Thu, 20 Feb 2025 19:23:49 +0300 Subject: [PATCH] feature/DO-1628_CICD_msg_test (!84) Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/84 Reviewed-by: Rustam Tagaev Reviewed-by: Denis Patrakeev --- .../Apps-Backend/msg-messenger-core-api.groovy | 13 +++++++++---- .../msg-messenger-core-api-deploy.groovy | 17 ++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pipelines/Cloud/Apps-Backend/msg-messenger-core-api.groovy b/pipelines/Cloud/Apps-Backend/msg-messenger-core-api.groovy index 46a8657..e60ad15 100644 --- a/pipelines/Cloud/Apps-Backend/msg-messenger-core-api.groovy +++ b/pipelines/Cloud/Apps-Backend/msg-messenger-core-api.groovy @@ -14,13 +14,18 @@ properties([ Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH) String repoPath = 'Apps-Backend/msg-messenger-core-api.git' -String publishBranch = 'develop' + +Map envBranch = [ + 'DEV': 'develop', + 'TEST': 'test' +] String dockerGroup = 'cloud' String dockerProject = 'msg-messenger-core-api' String projectSettingFile = 'pyproject.toml' Map gitVars = [:] String tag = '' String branch = git.getBranch() +String publishBranch = envBranch.find { it.value == branch }?.value Map configuration = [ vaultUrl: env.JENKINS_VAULT_URL, @@ -74,17 +79,17 @@ slaveTemplates.jnlp { "--build-arg PIP_INDEX_URL=${env.JENKINS_PIP_INDEX_URL} -f Dockerfile ." ) - if (branch == publishBranch) { + if (publishBranch.contains(branch)) { buildImage.push() } } } stage('deploy application'){ - if (branch == publishBranch){ + if (publishBranch.contains(branch)){ build job: 'Cloud/Deploy/Backend/msg-messenger-core-api-deploy', parameters: [ - string(name: 'ENV', value: 'DEV'), + string(name: 'ENV', value: envBranch.find { it.value == branch }?.key ), string(name: 'APP_VERSION', value: tag) ], wait: false diff --git a/pipelines/Cloud/Deploy/Backend/msg-messenger-core-api-deploy.groovy b/pipelines/Cloud/Deploy/Backend/msg-messenger-core-api-deploy.groovy index af57ae7..65d2007 100644 --- a/pipelines/Cloud/Deploy/Backend/msg-messenger-core-api-deploy.groovy +++ b/pipelines/Cloud/Deploy/Backend/msg-messenger-core-api-deploy.groovy @@ -9,6 +9,11 @@ String projectName = 'cloud' // Replace with your Harbor project name String repositoryName = 'msg-messenger-core-api' // Replace with your Harbor repository name String k8sAppName = repositoryName String pageSize = 100 // maximum number of artifacts to return 100 +Map envBranch = [ + 'DEV': 'develop', + 'TEST': 'test' +] + String apiUrl = "https://${JENKINS_DOCKER_REGISTRY}/api/v2.0/projects/${projectName}" + "/repositories/${repositoryName}/artifacts" properties([ @@ -20,7 +25,7 @@ properties([ parameters([ choice( name: 'ENV', - choices: ['DEV'], + choices: envBranch.keySet().toList(), description: 'Select one of environments' ), [$class: 'ChoiceParameter', @@ -70,10 +75,8 @@ return imageVersions ]) ]) - - String repoPath = 'Apps-Backend/msg-messenger-core-api.git' -String branch = 'develop' +String branch = envBranch.find { it.key == params.ENV }?.value String valuesPath = ".helm/values.${params.ENV.toLowerCase()}.yaml" String namespace = "tavro-cloud-${params.ENV.toLowerCase()}" @@ -81,11 +84,11 @@ String namespace = "tavro-cloud-${params.ENV.toLowerCase()}" String helmChart = 'msg-messenger-core-api' String helmRepoPath = "avroid/${helmChart}" String helmRepo = "${env.JENKINS_NEXUS_URL}/repository/devops-helm-release" - +println(branch) Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH) PodTemplates slaveTemplates = new PodTemplates(this, env.JENKINS_DOCKER_REGISTRY, - ["${env.JENKINS_K8S_HARBOR_SECRET}"], - 'avroid-office') + ["${env.JENKINS_K8S_HARBOR_SECRET}"], + 'avroid-office') slaveTemplates.jnlp { slaveTemplates.helm {