Files
coal/Jenkinsfile
2024-07-29 17:40:15 +08:00

81 lines
2.0 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
}
}
sh 'printenv'
}
}
stage("打包"){
steps{
sh 'printenv'
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}-${env.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}-${env.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}"
//
//
// }
//
// }
}
}