下面是我的管道:-
#!groovy
String version
String awsRegion = "us-east-1"
String appName = "abcde"
String dockerFilePath = "."
def featureEnv = env.BRANCH_NAME != 'master'
String branchName = env.BRANCH_NAME
String env = (env.BRANCH_NAME == 'master') ? 'release' : 'develop'
String ecrRepo = featureEnv ? "123456789012.dkr.ecr.${awsRegion}.amazonaws.com/abcde_${env}" : "987654321098.dkr.ecr.${awsRegion}.amazonaws.com/abcde_master"
String terraformPath = "terraform/dev"
println "Feature Environment=${featureEnv}"
pipeline {
agent none
options {
buildDiscarder(logRotator(numToKeepStr: '30'))
disableConcurrentBuilds()
timeout(time: 6, unit: 'HOURS')
ansiColor('xterm')
}
stages {
stage('version build'){
agent { label 'linux' }
steps {
script {
version = VersionNumber(
versionNumberString: '1.0.${BUILD_NUMBER, X}',
skipFailedBuilds: false)
currentBuild.displayName = version
println "Pipeline Version='${version}'"
}
}
}
stage('Build') {
when {
anyOf { branch 'develop'; branch 'release' }
}
agent { label 'linux' }
steps {
checkout scm
unstash name: "${appName}-docker"
dir(dockerFilePath) {
sh("""
while IFS= read -r line; do
build_args+=" --build-arg \$line"
done < "env_vars.txt"
#echo \$build_args
docker build -t ${ecrRepo}:${version} \$build_args --no-cache=true .
eval \$(aws ecr get-login --no-include-email --region ${awsRegion})
docker push ${ecrRepo}:${version}
docker rmi ${ecrRepo}:${version}
""")
}
}
}
}
}
我正在使用Multibranch管道执行Jenkins作业,但对于分支release
,默认情况下是develop
分支,我附加了Jenkins的docker build和docker push输出,而不是发布ECR存储库。请提出建议。
詹金斯输出:-
+ docker build -t 123456789012.dkr.ecr.us-east-1.amazonaws.com/abcde_develop:1.0.2 --build-arg HOST=0.0.0.0 --build-arg PORT=8080 --build-arg DOMAIN=abcde --build-arg MSAL_CLIENT_ID=1234567-bd11-4d2e-add5-d78f5e59e976 --build-arg
+ docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/abcde_develop:1.0.2
答案 0 :(得分:0)
假设您可以将此版本用于测试目的
when {
expression { BRANCH_NAME ==~ /(develop|release)/ }
}