refactor(pipelineCall): simplify configuration handling and improve readability
Signed-off-by: 孙振宇 <>
This commit is contained in:
parent
b9caf1d04e
commit
62fdc4c17a
19
first-class-pipeline/tests/Jenkinsfile
vendored
19
first-class-pipeline/tests/Jenkinsfile
vendored
@ -1,14 +1,13 @@
|
|||||||
#!groovy
|
#!groovy
|
||||||
|
|
||||||
library 'first-class-pipeline'
|
library 'first-class-pipeline'
|
||||||
def configurations = [:]
|
|
||||||
configurations.put('SERVICE_NAME', 'magicleaps')
|
|
||||||
configurations.put('SERVICE_LANG', 'Python')
|
|
||||||
configurations.put('SERVICE_GIT_REPO', 'https://freeleaps@dev.azure.com/freeleaps/magicleaps/_git/magicleaps')
|
|
||||||
configurations.put('SERVICE_GIT_BRANCH', 'master')
|
|
||||||
configurations.put('ENVIRONMENT_SLUG', 'alpha')
|
|
||||||
|
|
||||||
configurations.put('PY_DEPENDENCIES_MANAGER', 'PIP')
|
pipelineCall {
|
||||||
configurations.put('REQUIREMENTS_FILE_PATH', 'requirements.txt')
|
SERVICE_NAME = 'magicleaps'
|
||||||
|
SERVICE_LANG = 'Python'
|
||||||
pipelineCall(configurations)
|
SERVICE_GIT_BRANCH = 'master'
|
||||||
|
SERVICE_GIT_REPO = "https://freeleaps@dev.azure.com/freeleaps/magicleaps/_git/magicleaps",
|
||||||
|
ENVIRONMENT_SLUG = 'alpha'
|
||||||
|
PY_DEPENDENCIES_MANAGER = 'PIP'
|
||||||
|
REQUIREMENTS_FILE_PATH = 'requirements.txt'
|
||||||
|
}
|
||||||
@ -5,7 +5,12 @@ import com.freeleaps.devops.SourceFetcher
|
|||||||
import com.freeleaps.devops.DependenciesResolver
|
import com.freeleaps.devops.DependenciesResolver
|
||||||
import com.freeleaps.devops.enums.DependenciesManager
|
import com.freeleaps.devops.enums.DependenciesManager
|
||||||
|
|
||||||
def call(Map configurations) {
|
def call(configurations) {
|
||||||
|
def configurationMap = [:]
|
||||||
|
configurations.resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
|
configurations.delegate = configurationMap
|
||||||
|
configurations()
|
||||||
|
|
||||||
def environmentVars = new EnvironmentVars(this)
|
def environmentVars = new EnvironmentVars(this)
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
@ -21,7 +26,7 @@ def call(Map configurations) {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def sourceFetcher = new SourceFetcher(this)
|
def sourceFetcher = new SourceFetcher(this)
|
||||||
sourceFetcher.fetch(configurations)
|
sourceFetcher.fetch(configurationMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -29,7 +34,7 @@ def call(Map configurations) {
|
|||||||
stage("Prepared Environment Variables") {
|
stage("Prepared Environment Variables") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
environmentVars.injectVars(configurations)
|
environmentVars.injectVars(configurationMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +54,7 @@ def call(Map configurations) {
|
|||||||
stage("Build Agent Setup") {
|
stage("Build Agent Setup") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def buildAgentImage = configurations.BUILD_AGENT_IMAGE
|
def buildAgentImage = configurationMap.BUILD_AGENT_IMAGE
|
||||||
if (buildAgentImage != null && !buildAgentImage.isEmpty()) {
|
if (buildAgentImage != null && !buildAgentImage.isEmpty()) {
|
||||||
echo "Not set BUILD_AGENT_IMAGE, using default build agent image"
|
echo "Not set BUILD_AGENT_IMAGE, using default build agent image"
|
||||||
|
|
||||||
@ -99,7 +104,7 @@ spec:
|
|||||||
script {
|
script {
|
||||||
def language = env.SERVICE_LANG
|
def language = env.SERVICE_LANG
|
||||||
|
|
||||||
def depManager = DependenciesManager.parse(configurations.DEPENDENCIES_MANAGER)
|
def depManager = DependenciesManager.parse(configurationMap.DEPENDENCIES_MANAGER)
|
||||||
if (depManager == DependenciesManager.UNKNOWN) {
|
if (depManager == DependenciesManager.UNKNOWN) {
|
||||||
error("Unknown dependencies manager")
|
error("Unknown dependencies manager")
|
||||||
}
|
}
|
||||||
@ -107,13 +112,13 @@ spec:
|
|||||||
def dependenciesResolver = new DependenciesResolver(this, language)
|
def dependenciesResolver = new DependenciesResolver(this, language)
|
||||||
dependenciesResolver.useManager(depManager)
|
dependenciesResolver.useManager(depManager)
|
||||||
|
|
||||||
if (configurations.BUILD_CACHE_ENABLED == "true") {
|
if (configurationMap.BUILD_CACHE_ENABLED == "true") {
|
||||||
dependenciesResolver.enableCachingSupport()
|
dependenciesResolver.enableCachingSupport()
|
||||||
} else {
|
} else {
|
||||||
dependenciesResolver.disableCachingSupport()
|
dependenciesResolver.disableCachingSupport()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesResolver.resolve(configurations)
|
dependenciesResolver.resolve(configurationMap)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user