diff --git a/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy b/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy index f0c41e4d..996c6a5f 100644 --- a/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy +++ b/first-class-pipeline/src/com/freeleaps/devops/ArgoApplicationVersionUpdater.groovy @@ -13,14 +13,35 @@ class ArgoApplicationVersionUpdater { def update(environmentSlug, component) { steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] Update Argo application image version to ${steps.env.BUILD_IMAGE_VERSION} for ${component.name}...") - steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] Pull freeleaps-ops repository to workspace...") + + def userSpecifiedArgoControlledRepo = false + def argoControlledRepo = configurations.argoControlledRepo + if (argoControlledRepo != null && !argoControlledRepo.isEmpty()) { + userSpecifiedArgoControlledRepo = true + } + + def repoUrl = "https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops.git" + def repoCredentialsId = "freeleaps-ops-credentials" + def repoBranch = "master" + def valuesFile = "./${configurations.serviceName}/helm-pkg/${component.name}/values.${environmentSlug}.yaml" + + if (userSpecifiedArgoControlledRepo) { + repoUrl = component.argoControlledRepo + repoCredentialsId = component.argoControlledRepoCredentialsId + repoBranch = component.argoControlledRepoBranch + valuesFile = ".freeleaps/devops/helm-pkg/values.${environmentSlug}.yaml" + steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] User specified argo controlled repo: ${argoControlledRepo}") + } else { + steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] Using default argo controlled repo: freeleaps-ops") + } + + steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] Pull argo controlled repo from ${repoUrl} to workspace...") steps.dir("${workspace}") { - steps.git branch: 'master', credentialsId: 'freeleaps-ops-credentials', url: 'https://gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops.git' + steps.git branch: repoBranch, credentialsId: repoCredentialsId, url: repoUrl } steps.dir("${workspace}") { - def valuesFile = "./${configurations.serviceName}/helm-pkg/${component.name}/values.${environmentSlug}.yaml" steps.log.info("ArgoApplicationVersionUpdater", "[${environmentSlug}] Update ${valuesFile}...") def data = steps.readYaml(file: valuesFile) data[component.name].image.registry = steps.env.BUILD_IMAGE_REGISTRY @@ -29,7 +50,13 @@ class ArgoApplicationVersionUpdater { data[component.name].image.name = steps.env.BUILD_IMAGE_NAME steps.writeYaml(file: valuesFile, data: data, overwrite: true) - steps.withCredentials([steps.usernamePassword(credentialsId: 'freeleaps-ops-credentials', passwordVariable: 'OPS_GIT_PASSWORD', usernameVariable: 'OPS_GIT_USERNAME')]) { + steps.withCredentials([steps.usernamePassword(credentialsId: repoCredentialsId, passwordVariable: 'OPS_GIT_PASSWORD', usernameVariable: 'OPS_GIT_USERNAME')]) { + ciOriginUrl = "https://${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops.git" + if (userSpecifiedArgoControlledRepo) { + // argoControlledRepo is a git url, so we need add username and password to the url + def argoControlledRepoUrlObj = new URL(component.argoControlledRepo) + ciOriginUrl = "${argoControlledRepoUrlObj.protocol}://${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@${argoControlledRepoUrlObj.host}${argoControlledRepoUrlObj.path}" + } steps.sh """ #!/bin/bash @@ -41,7 +68,7 @@ class ArgoApplicationVersionUpdater { git config user.email "gitops@mathmast.com" echo "Add and commit changes..." - git remote add ci_origin https://${steps.env.OPS_GIT_USERNAME}:${steps.env.OPS_GIT_PASSWORD}@gitea.freeleaps.mathmast.com/freeleaps/freeleaps-ops.git + git remote add ci_origin ${ciOriginUrl} git add ${valuesFile} @@ -53,7 +80,7 @@ class ArgoApplicationVersionUpdater { fi echo "Push changes to freeleaps-ops repository..." - git push ci_origin HEAD:master + git push ci_origin HEAD:${repoBranch} echo "Done." """