refactor(DependenciesResolver, EnvironmentVars, SourceFetcher, pipelineCall): standardize configuration property names to camelCase
Signed-off-by: 孙振宇 <>
This commit is contained in:
parent
62fdc4c17a
commit
2d2cf27318
@ -28,7 +28,7 @@ class DependenciesResolver {
|
|||||||
this.mgr = mgr
|
this.mgr = mgr
|
||||||
}
|
}
|
||||||
|
|
||||||
def resolve(Map configurations) {
|
def resolve(configurations) {
|
||||||
if (mgr == null) {
|
if (mgr == null) {
|
||||||
steps.error("Dependencies manager is not set")
|
steps.error("Dependencies manager is not set")
|
||||||
}
|
}
|
||||||
@ -43,11 +43,11 @@ class DependenciesResolver {
|
|||||||
|
|
||||||
switch (mgr) {
|
switch (mgr) {
|
||||||
case DependenciesManager.PIP:
|
case DependenciesManager.PIP:
|
||||||
if (configurations.PIP_REQUIREMENTS_FILE == null || configurations.PIP_REQUIREMENTS_FILE.isEmpty()) {
|
if (configurations.pipRequirementsFile == null || configurations.pipRequirementsFile.isEmpty()) {
|
||||||
steps.error("PIP_REQUIREMENTS_FILE is required when using PIP as dependencies manager")
|
steps.error("pipRequirementsFile is required when using PIP as dependencies manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
def requirementsFile = configurations.PIP_REQUIREMENTS_FILE
|
def requirementsFile = configurations.pipRequirementsFile
|
||||||
|
|
||||||
if (cachingEnabled) {
|
if (cachingEnabled) {
|
||||||
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.pip-cache']]) {
|
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.pip-cache']]) {
|
||||||
@ -57,11 +57,11 @@ class DependenciesResolver {
|
|||||||
steps.sh "pip install -r ${requirementsFile}"
|
steps.sh "pip install -r ${requirementsFile}"
|
||||||
}
|
}
|
||||||
case DependenciesManager.NPM:
|
case DependenciesManager.NPM:
|
||||||
if (configurations.NPM_PACKAGE_JSON_FILE == null || configurations.NPM_PACKAGE_JSON_FILE.isEmpty()) {
|
if (configurations.npmPackageJsonFile == null || configurations.npmPackageJsonFile.isEmpty()) {
|
||||||
steps.error("NPM_PACKAGE_JSON_FILE is required when using NPM as dependencies manager")
|
steps.error("npmPackageJsonFile is required when using NPM as dependencies manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
def packageJsonFile = configurations.NPM_PACKAGE_JSON_FILE
|
def packageJsonFile = configurations.npmPackageJsonFile
|
||||||
|
|
||||||
if (cachingEnabled) {
|
if (cachingEnabled) {
|
||||||
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.npm-cache']]) {
|
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.npm-cache']]) {
|
||||||
@ -71,11 +71,11 @@ class DependenciesResolver {
|
|||||||
steps.sh "npm install"
|
steps.sh "npm install"
|
||||||
}
|
}
|
||||||
case DependenciesManager.YARN:
|
case DependenciesManager.YARN:
|
||||||
if (configurations.YARN_PACKAGE_JSON_FILE == null || configurations.YARN_PACKAGE_JSON_FILE.isEmpty()) {
|
if (configurations.yarnPackageJsonFile == null || configurations.yarnPackageJsonFile.isEmpty()) {
|
||||||
steps.error("YARN_PACKAGE_JSON_FILE is required when using YARN as dependencies manager")
|
steps.error("yarnPackageJsonFile is required when using YARN as dependencies manager")
|
||||||
}
|
}
|
||||||
|
|
||||||
def packageJsonFile = configurations.YARN_PACKAGE_JSON_FILE
|
def packageJsonFile = configurations.yarnPackageJsonFile
|
||||||
|
|
||||||
if (cachingEnabled) {
|
if (cachingEnabled) {
|
||||||
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.yarn-cache']]) {
|
steps.cache(maxCacheSize: 512, caches: [[$class: 'ArbitraryFileCache', excludes: '', includes: '**/*', path: '.yarn-cache']]) {
|
||||||
|
|||||||
@ -9,30 +9,30 @@ class EnvironmentVars {
|
|||||||
this.steps = steps
|
this.steps = steps
|
||||||
}
|
}
|
||||||
|
|
||||||
def injectVars(Map configurations) {
|
def injectVars(configurations) {
|
||||||
if (configurations.SERVICE_NAME == null || configurations.SERVICE_NAME.isEmpty()) {
|
if (configurations.serviceName == null || configurations.serviceName.isEmpty()) {
|
||||||
steps.error("SERVICE_NAME is required")
|
steps.error("serviceName is required")
|
||||||
}
|
}
|
||||||
steps.env.SERVICE_NAME = configurations.SERVICE_NAME
|
steps.env.serviceName = configurations.serviceName
|
||||||
|
|
||||||
steps.env.SERVICE_LANG = ServiceLanguage.parse(configurations.SERVICE_LANG)
|
steps.env.serviceLang = ServiceLanguage.parse(configurations.serviceLang)
|
||||||
if (steps.env.SERVICE_LANG == ServiceLanguage.UNKNOWN) {
|
if (steps.env.serviceLang == ServiceLanguage.UNKNOWN) {
|
||||||
steps.error("Unknown service language: ${configurations.SERVICE_LANG}")
|
steps.error("Unknown service language: ${configurations.serviceLang}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configurations.SERVICE_GIT_REPO == null || configurations.SERVICE_GIT_REPO.isEmpty()) {
|
if (configurations.serviceGitRepo == null || configurations.serviceGitRepo.isEmpty()) {
|
||||||
steps.error("SERVICE_GIT_REPO is required")
|
steps.error("serviceGitRepo is required")
|
||||||
}
|
}
|
||||||
steps.env.SERVICE_GIT_REPO = configurations.SERVICE_GIT_REPO
|
steps.env.serviceGitRepo = configurations.serviceGitRepo
|
||||||
|
|
||||||
if (configurations.SERVICE_GIT_BRANCH == null || configurations.SERVICE_GIT_BRANCH.isEmpty()) {
|
if (configurations.serviceGitBranch == null || configurations.serviceGitBranch.isEmpty()) {
|
||||||
steps.error("SERVICE_GIT_BRANCH is required")
|
steps.error("serviceGitBranch is required")
|
||||||
}
|
}
|
||||||
steps.env.SERVICE_GIT_BRANCH = configurations.SERVICE_GIT_BRANCH
|
steps.env.serviceGitBranch = configurations.serviceGitBranch
|
||||||
|
|
||||||
if (configurations.ENVIRONMENT_SLUG == null || configurations.ENVIRONMENT_SLUG.isEmpty()) {
|
if (configurations.environmentSlug == null || configurations.environmentSlug.isEmpty()) {
|
||||||
steps.error("ENVIRONMENT_SLUG is required")
|
steps.error("environmentSlug is required")
|
||||||
}
|
}
|
||||||
steps.env.ENVIRONMENT_SLUG = configurations.ENVIRONMENT_SLUG
|
steps.env.environmentSlug = configurations.environmentSlug
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,16 +7,16 @@ class SourceFetcher {
|
|||||||
this.steps = steps
|
this.steps = steps
|
||||||
}
|
}
|
||||||
|
|
||||||
def fetch(Map configurations) {
|
def fetch(configurations) {
|
||||||
echo configurations
|
echo configurations
|
||||||
if (configurations.SERVICE_GIT_REPO == null || configurations.SERVICE_GIT_REPO.isEmpty()) {
|
if (configurations.serviceGitRepo == null || configurations.serviceGitRepo.isEmpty()) {
|
||||||
steps.error("SERVICE_GIT_REPO is required")
|
steps.error("serviceGitRepo is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configurations.SERVICE_GIT_BRANCH == null || configurations.SERVICE_GIT_BRANCH.isEmpty()) {
|
if (configurations.serviceGitBranch == null || configurations.serviceGitBranch.isEmpty()) {
|
||||||
steps.error("SERVICE_GIT_BRANCH is required")
|
steps.error("serviceGitBranch is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
steps.git branch: configurations.SERVICE_GIT_BRANCH, credentialsId: 'git-bot-credentials', url: configurations.SERVICE_GIT_REPO
|
steps.git branch: configurations.serviceGitBranch, credentialsId: 'git-bot-credentials', url: configurations.serviceGitRepo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
first-class-pipeline/tests/Jenkinsfile
vendored
14
first-class-pipeline/tests/Jenkinsfile
vendored
@ -3,11 +3,11 @@
|
|||||||
library 'first-class-pipeline'
|
library 'first-class-pipeline'
|
||||||
|
|
||||||
pipelineCall {
|
pipelineCall {
|
||||||
SERVICE_NAME = 'magicleaps'
|
serviceName = 'magicleaps'
|
||||||
SERVICE_LANG = 'Python'
|
serviceLang = 'Python'
|
||||||
SERVICE_GIT_BRANCH = 'master'
|
serviceGitBranch = 'master'
|
||||||
SERVICE_GIT_REPO = "https://freeleaps@dev.azure.com/freeleaps/magicleaps/_git/magicleaps",
|
serviceGitRepo = "https://freeleaps@dev.azure.com/freeleaps/magicleaps/_git/magicleaps",
|
||||||
ENVIRONMENT_SLUG = 'alpha'
|
environmentSlug = 'alpha'
|
||||||
PY_DEPENDENCIES_MANAGER = 'PIP'
|
dependenciesManager = 'PIP'
|
||||||
REQUIREMENTS_FILE_PATH = 'requirements.txt'
|
pipRequirementsFile = 'requirements.txt'
|
||||||
}
|
}
|
||||||
@ -5,11 +5,11 @@ 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(configurations) {
|
def call(body) {
|
||||||
def configurationMap = [:]
|
def configurations = [:]
|
||||||
configurations.resolveStrategy = Closure.DELEGATE_FIRST
|
body.resolveStrategy = Closure.DELEGATE_FIRST
|
||||||
configurations.delegate = configurationMap
|
body.delegate = configurations
|
||||||
configurations()
|
body()
|
||||||
|
|
||||||
def environmentVars = new EnvironmentVars(this)
|
def environmentVars = new EnvironmentVars(this)
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ def call(configurations) {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def sourceFetcher = new SourceFetcher(this)
|
def sourceFetcher = new SourceFetcher(this)
|
||||||
sourceFetcher.fetch(configurationMap)
|
sourceFetcher.fetch(configurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ def call(configurations) {
|
|||||||
stage("Prepared Environment Variables") {
|
stage("Prepared Environment Variables") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
environmentVars.injectVars(configurationMap)
|
environmentVars.injectVars(configurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ def call(configurations) {
|
|||||||
stage("Commit Linting If Enabled") {
|
stage("Commit Linting If Enabled") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def enabled = configurations.COMMIT_MESSAGE_LINT_ENABLED
|
def enabled = configurations.commitMessageLintEnabled
|
||||||
|
|
||||||
if (enabled != null && enabled == "true") {
|
if (enabled != null && enabled == "true") {
|
||||||
print("Commit Linting is enabled")
|
print("Commit Linting is enabled")
|
||||||
@ -54,11 +54,11 @@ def call(configurations) {
|
|||||||
stage("Build Agent Setup") {
|
stage("Build Agent Setup") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def buildAgentImage = configurationMap.BUILD_AGENT_IMAGE
|
def buildAgentImage = configurations.buildAgentImage
|
||||||
if (buildAgentImage != null && !buildAgentImage.isEmpty()) {
|
if (buildAgentImage != null && !buildAgentImage.isEmpty()) {
|
||||||
echo "Not set BUILD_AGENT_IMAGE, using default build agent image"
|
echo "Not set buildAgentImage, using default build agent image"
|
||||||
|
|
||||||
def language = env.SERVICE_LANG
|
def language = env.serviceLang
|
||||||
switch(language) {
|
switch(language) {
|
||||||
case PYTHON:
|
case PYTHON:
|
||||||
buildAgentImage = "python:3.10-slim-buster"
|
buildAgentImage = "python:3.10-slim-buster"
|
||||||
@ -68,7 +68,7 @@ def call(configurations) {
|
|||||||
error("Unknown service language")
|
error("Unknown service language")
|
||||||
}
|
}
|
||||||
|
|
||||||
env.BUILD_AGENT_IMAGE = buildAgentImage
|
env.buildAgentImage = buildAgentImage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: dep-resolver
|
- name: dep-resolver
|
||||||
image: ${env.BUILD_AGENT_IMAGE}
|
image: ${env.buildAgentImage}
|
||||||
command:
|
command:
|
||||||
- cat
|
- cat
|
||||||
tty: true
|
tty: true
|
||||||
@ -102,9 +102,9 @@ spec:
|
|||||||
}
|
}
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
def language = env.SERVICE_LANG
|
def language = env.serviceLang
|
||||||
|
|
||||||
def depManager = DependenciesManager.parse(configurationMap.DEPENDENCIES_MANAGER)
|
def depManager = DependenciesManager.parse(configurations.dependenciesManager)
|
||||||
if (depManager == DependenciesManager.UNKNOWN) {
|
if (depManager == DependenciesManager.UNKNOWN) {
|
||||||
error("Unknown dependencies manager")
|
error("Unknown dependencies manager")
|
||||||
}
|
}
|
||||||
@ -112,13 +112,13 @@ spec:
|
|||||||
def dependenciesResolver = new DependenciesResolver(this, language)
|
def dependenciesResolver = new DependenciesResolver(this, language)
|
||||||
dependenciesResolver.useManager(depManager)
|
dependenciesResolver.useManager(depManager)
|
||||||
|
|
||||||
if (configurationMap.BUILD_CACHE_ENABLED == "true") {
|
if (configurations.BUILD_CACHE_ENABLED == "true") {
|
||||||
dependenciesResolver.enableCachingSupport()
|
dependenciesResolver.enableCachingSupport()
|
||||||
} else {
|
} else {
|
||||||
dependenciesResolver.disableCachingSupport()
|
dependenciesResolver.disableCachingSupport()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependenciesResolver.resolve(configurationMap)
|
dependenciesResolver.resolve(configurations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user