freeleaps-ops/first-class-pipeline/src/com/freeleaps/devops/EnvironmentVars.groovy

38 lines
1.2 KiB
Groovy
Raw Normal View History

package com.freeleaps.devops
import com.freeleaps.devops.enums.ServiceLanguage
class EnvironmentVars {
def steps
EnvironmentVars(steps) {
this.steps = steps
}
def injectVars(Map configurations) {
if (steps.env.SERVICE_NAME == null || steps.env.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 (steps.env.SERVICE_GIT_REPO == null || steps.env.SERVICE_GIT_REPO.isEmpty()) {
steps.error("SERVICE_GIT_REPO is required")
}
steps.env.SERVICE_GIT_REPO = configurations.SERVICE_GIT_REPO
if (steps.env.SERVICE_GIT_BRANCH == null || steps.env.SERVICE_GIT_BRANCH.isEmpty()) {
steps.error("SERVICE_GIT_BRANCH is required")
}
steps.env.SERVICE_GIT_BRANCH = configurations.SERVICE_GIT_BRANCH
if (steps.env.ENVIRONMENT_SLUG == null || steps.env.ENVIRONMENT_SLUG.isEmpty()) {
steps.error("ENVIRONMENT_SLUG is required")
}
steps.env.ENVIRONMENT_SLUG = configurations.ENVIRONMENT_SLUG
}
}