freeleaps-ops/first-class-pipeline/src/com/freeleaps/devops/EnvironmentVars.groovy
2025-01-21 17:01:31 +08:00

38 lines
1.3 KiB
Groovy

package com.freeleaps.devops
import com.freeleaps.devops.enums.ServiceLanguage
class EnvironmentVars {
def steps
EnvironmentVars(steps) {
this.steps = steps
}
def injectVars(Map configurations) {
if (configurations.SERVICE_NAME == null || configurations.SERVICE_NAME.isEmpty()) {
steps.error("SERVICE_NAME is required")
}
steps.env.SERVICE_NAME = configurations.SERVICE_NAME
steps.env.SERVICE_LANG = ServiceLanguage.parse(configurations.SERVICE_LANG)
if (steps.env.SERVICE_LANG == ServiceLanguage.UNKNOWN) {
steps.error("Unknown service language: ${configurations.SERVICE_LANG}")
}
if (configurations.SERVICE_GIT_REPO == null || configurations.SERVICE_GIT_REPO.isEmpty()) {
steps.error("SERVICE_GIT_REPO is required")
}
steps.env.SERVICE_GIT_REPO = configurations.SERVICE_GIT_REPO
if (configurations.SERVICE_GIT_BRANCH == null || configurations.SERVICE_GIT_BRANCH.isEmpty()) {
steps.error("SERVICE_GIT_BRANCH is required")
}
steps.env.SERVICE_GIT_BRANCH = configurations.SERVICE_GIT_BRANCH
if (configurations.ENVIRONMENT_SLUG == null || configurations.ENVIRONMENT_SLUG.isEmpty()) {
steps.error("ENVIRONMENT_SLUG is required")
}
steps.env.ENVIRONMENT_SLUG = configurations.ENVIRONMENT_SLUG
}
}