From e851f2b4eea43489c6758248c106b4c51b64821a Mon Sep 17 00:00:00 2001 From: lihongjie0209 Date: Mon, 29 Jul 2024 16:58:27 +0800 Subject: [PATCH] bugfix --- Jenkinsfile | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 85a86400..be6c8ea7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,13 +8,6 @@ pipeline{ } - parameters { - string( - name: 'BUILD_TIME', - defaultValue: new Date().format("yyyy-MM-dd-HH-mm-ss", TimeZone.getTimeZone("Asia/Shanghai")), - description: 'Build time in UTC' - ) - } triggers { @@ -22,6 +15,25 @@ pipeline{ } stages{ + stage('定义变量') { + steps { + script { + // 获取当前时间 + + def now = new Date() + + // 格式化时间,例如为 yyyy-MM-dd HH:mm:ss + def timeFormatter = new java.text.SimpleDateFormat("yyyy-MM-dd-HH-mm-ss") + def currentTime = timeFormatter.format(now) + + // 将格式化的当前时间存储为环境变量 + environment { + CURRENT_TIME = currentTime + } + } + } + } + stage("打包"){ @@ -32,9 +44,9 @@ pipeline{ sh "docker login -u ${u} -p ${p} registry.cn-beijing.aliyuncs.com" } sh "docker build . -t registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-latest" - sh "docker tag registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-latest registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-${params.BUILD_TIME}" + sh "docker tag registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-latest registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-${params.CURRENT_TIME}" sh "docker push registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-latest" - sh "docker push registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-${params.BUILD_TIME}" + sh "docker push registry.cn-beijing.aliyuncs.com/lihongjie/coal:${env.BRANCH_NAME}-${params.CURRENT_TIME}" }