这是Jenkins文件
@Library('shared-library@variablestatus')
def IMG_NAME = 'shortener'
def REPO_URL = ''
(BRANCH, CLUSTER, NAMESPACE, ENVPROFILE, REGION, ECR_REGISTRY, BUILDFLAG, DEPLOYFLAG) = getEnvParams("system")
properties([
parameters([
string(name: 'GIT_REVISION', description: 'Git branch or commit to fetch.', defaultValue: "$BRANCH", trim: true),
booleanParam(name: 'BUILD', description: 'Whether to build and publish the image. If disabled, deployment will use latest available image.', defaultValue: "${BUILDFLAG}"),
booleanParam(name: 'DEPLOY', description: 'Whether to deploy the image to EKS.', defaultValue: "${DEPLOYFLAG}")
])
])
node('ec2') {
stage('checkout') {
gitCommit = gitCheckout(this, "$REPO_URL", params.GIT_REVISION)
}
stage("build") {
withFolderProperties{
withCredentials([sshUserPrivateKey(credentialsId: 'eksgit', keyFileVariable: 'EKSGIT')]) {
if (fileExists('eksgit')) {
sh 'rm -rf eksgit'
}
sh "cp \$EKSGIT eksgit"
sh "envsubst < env.tmpl > .env"
}
}
buildTag = buildECRImage(this, params.BUILD, "$ENVPROFILE", "$BUILD_NUMBER", "$REGION", "$ECR_REGISTRY", "$IMG_NAME", gitCommit)
}
stage("deploy") {
if (params.DEPLOY) {
deployToEKS("$REGION", "$CLUSTER", "$ENVPROFILE" , "$NAMESPACE", "$ECR_REGISTRY", "$IMG_NAME", buildTag)
publishReleaseTag(this, buildTag)
}
}
stage("cleanup") {
cleanupBuild(this)
}
}
共享库getEnvParameter函数代码如下:
def call(String jobtype) {
// Get current environment name based on the job path.
def jobenv = "$env.JOB_NAME".split('/').first()
if (jobtype == "conversion") {
// Environment params used in conversion server pipelines.
def env = ''
def branch = 'dev'
def serverFilter = 'all'
def dockerHubUser = ''
if (jobenv == 'production') {
branch = 'master'
env = 'production'
serverFilter = ''
} else if (jobenv == 'Development') {
env = 'dev'
} else if (jobenv == 'msofficeprod') {
env = 'qa2'
} else {
env = jobenv
}
return [env, branch, serverFilter, dockerHubUser]
}
else if (jobtype == "system") {
// Environment params used in EKS pipeliness (a.k.a system services).
def branch = 'dev'
def kubeCluster = 'devstage'
def kubeNamespace = ''
def envProfile = ''
def region = 'us-east-2'
def ecrRegistry = ''
def buildflag = true
def deployflag = true
if (jobenv == 'production') {
branch = 'master'
kubeCluster = 'convert'
kubeNamespace = 'prod'
envProfile = 'prod'
buildflag = false
deployflag = false
} else if (jobenv == 'Development') {
kubeNamespace = 'development'
envProfile = 'stage'
}
else {
kubeNamespace = jobenv
envProfile = jobenv
}
return [branch, kubeCluster, kubeNamespace, envProfile, region, ecrRegistry]
}
else {
error "Invalid jobtype specified for env param retrieval: $jobtype"
return 1
}
}
问题是我无法使用defaultValue设置boolean参数的默认值:“${BUILDFLAG}”此语法形成共享库。它不是覆盖。我需要使用jenkins管道中的共享库ovveride默认值。
1条答案
按热度按时间2skhul331#
我没有在return语句中添加这些变量