This commit is contained in:
2024-07-29 16:58:27 +08:00
parent b8e4e2c52b
commit e851f2b4ee

30
Jenkinsfile vendored
View File

@@ -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}"
}