pipeline{ agent any options { disableConcurrentBuilds() } environment{ CURRENT_TIME = """${sh( returnStdout: true, script: 'date "+%Y-%m-%d-%H-%M-%S"' )}""" } triggers { pollSCM 'H/3 * * * * ' GenericTrigger( genericVariables: [ [key: 'ref', value: '$.ref'] ], causeString: 'Triggered on $ref', token: GIT_URL.split('/')[-1].split('.git')[0], tokenCredentialId: '', printContributedVariables: true, printPostContent: true, silentResponse: false, shouldNotFlatten: false, regexpFilterText: '$ref', regexpFilterExpression: 'refs/heads/' + BRANCH_NAME ) } stages{ 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}" // // // } // // } } }