mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
76 lines
1.9 KiB
Groovy
76 lines
1.9 KiB
Groovy
pipeline{
|
|
|
|
agent any
|
|
|
|
options {
|
|
|
|
disableConcurrentBuilds()
|
|
}
|
|
|
|
|
|
|
|
|
|
triggers {
|
|
pollSCM 'H/3 * * * * '
|
|
}
|
|
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("打包"){
|
|
|
|
|
|
steps{
|
|
withCredentials([usernamePassword(credentialsId: 'aliyun_cr_lihongjie', passwordVariable: 'p', usernameVariable: 'u')]) {
|
|
|
|
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}-${evn.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}-${evn.CURRENT_TIME}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// stage("重新部署"){
|
|
//
|
|
//
|
|
// steps{
|
|
//
|
|
// sh "kubectl --kubeconfig=homelab.yaml apply -k k8s/${env.BRANCH_NAME}/"
|
|
// sh "kubectl --kubeconfig=homelab.yaml rollout restart deployment/coal-api --namespace coal-${env.BRANCH_NAME}"
|
|
//
|
|
//
|
|
// }
|
|
//
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
} |