优化
This commit is contained in:
+13
-4
@@ -33,7 +33,6 @@ pipeline {
|
||||
}
|
||||
|
||||
parameters {
|
||||
choice(name: 'SERVICE', choices: serviceModules, description: '本 Job 负责构建和部署的单个服务')
|
||||
string(name: 'SOURCE_COMMIT', defaultValue: '', description: '必须构建的 Git commit;通常由总控 Job 传入')
|
||||
string(name: 'IMAGE_TAG', defaultValue: '', description: '不可变镜像标签;通常使用 Git commit 前 12 位')
|
||||
choice(name: 'ENVIRONMENT', choices: ['test', 'staging', 'production'], description: '部署环境')
|
||||
@@ -52,14 +51,25 @@ pipeline {
|
||||
stages {
|
||||
stage('校验参数并检出指定提交') {
|
||||
steps {
|
||||
checkout scm
|
||||
|
||||
script {
|
||||
String service = params.SERVICE?.trim()
|
||||
String service = serviceModules.find { candidate ->
|
||||
env.JOB_BASE_NAME?.endsWith("-${candidate}")
|
||||
}
|
||||
String sourceCommit = params.SOURCE_COMMIT?.trim()
|
||||
String imageTag = params.IMAGE_TAG?.trim()
|
||||
String imageRepository = params.IMAGE_REPOSITORY?.trim()
|
||||
|
||||
if (!sourceCommit) {
|
||||
sourceCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).trim()
|
||||
}
|
||||
if (!imageTag) {
|
||||
imageTag = sh(script: 'git rev-parse --short=12 HEAD', returnStdout: true).trim()
|
||||
}
|
||||
|
||||
if (!serviceModules.contains(service)) {
|
||||
error("未知服务: ${service};允许值: ${serviceModules.join(', ')}")
|
||||
error("无法从 Job 名称 ${env.JOB_BASE_NAME} 识别服务;名称必须以以下服务之一结尾: ${serviceModules.join(', ')}")
|
||||
}
|
||||
if (!sourceCommit || !(sourceCommit ==~ /(?i)[0-9a-f]{7,40}/)) {
|
||||
error('SOURCE_COMMIT 必须是 7 到 40 位十六进制 Git commit')
|
||||
@@ -80,7 +90,6 @@ pipeline {
|
||||
env.RESOLVED_IMAGE_REPOSITORY = imageRepository
|
||||
}
|
||||
|
||||
checkout scm
|
||||
sh '''
|
||||
if ! git cat-file -e "${RESOLVED_SOURCE_COMMIT}^{commit}" 2>/dev/null; then
|
||||
git fetch --no-tags origin
|
||||
|
||||
Reference in New Issue
Block a user