1 Star 0 Fork 0

funnywus/jenkins-test

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Jenkinsfile 2.96 KB
一键复制 编辑 原始数据 按行查看 历史
lemonboxDev 提交于 2023-09-12 13:53 . init
pipeline {
environment {
mavenRegistry = "registry-vpc.cn-beijing.aliyuncs.com/lemonbox/questionnaire_setting_maven"
registry = "registry-vpc.cn-beijing.aliyuncs.com/lemonbox/questionnaire-java"
registryCredential = "dockerhub"
parentWorkspace = "$WORKSPACE"
FAILED_STAGE=""
CURRENT_ENVIRONMENT=""
BLUE_OR_GREEN=""
}
agent any
stages {
stage("Deply Parent") {
agent {
docker {
image mavenRegistry
registryUrl 'https://registry-vpc.cn-beijing.aliyuncs.com'
registryCredentialsId registryCredential
args '-v $HOME/.m2/repository:/root/.m2/repository -u root'
}
}
steps {
script {
FAILED_STAGE=env.STAGE_NAME
sh "mvn -U clean install -Dmaven.test.skip=true"
// 拷贝到容器外
sh "cp target/questionnaire-release-exec.jar " + parentWorkspace +"/questionnaire-release-exec.jar"
}
}
}
stage("Building image") {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
docker.build(registry)
}
}
}
stage("Deploy Image") {
steps {
script {
FAILED_STAGE=env.STAGE_NAME
docker.withRegistry('https://registry-vpc.cn-beijing.aliyuncs.com', registryCredential) {
docker.image(registry).push("$GIT_COMMIT")
}
}
}
}
stage("Update k8s cluster") {
options {
timeout(time: 8, unit: 'MINUTES')
}
steps {
script {
FAILED_STAGE = env.STAGE_NAME
if (env.GIT_BRANCH == "origin/master") {
sh "kubectl config use 229638354516261836-c1ef3c2118ae344d3b5ee63c17ae6f93b"
sh "cat k8s/deployment.yml | sed 's/{{GIT_COMMIT}}/$GIT_COMMIT/g' | kubectl apply -f -"
sh "kubectl rollout status deployment/questionnaire-java"
} else {
sh "kubectl config use test"
sh "cat k8s/deployment-test.yml | sed 's/{{GIT_COMMIT}}/$GIT_COMMIT/g' | kubectl apply -f -"
sh "kubectl rollout status deployment/questionnaire-java-test"
}
}
}
}
}
post {
failure {
sh "curl -d '{\"commitId\": \"$GIT_COMMIT\", \"branch\": \"$GIT_BRANCH\", \"build\": \"$BUILD_ID\"}' -H \"Content-Type: application/json\" -X POST http://ec2-54-222-181-255.cn-north-1.compute.amazonaws.com.cn:6666/build/fail"
}
aborted {
script {
if (FAILED_STAGE == "Update k8s cluster") {
if (env.GIT_BRANCH == "origin/master") {
sh "kubectl config use 229638354516261836-c1ef3c2118ae344d3b5ee63c17ae6f93b"
sh "kubectl rollout undo deployment/questionnaire-java"
} else {
sh "kubectl config use test"
sh "kubectl rollout undo deployment/questionnaire-java-test"
}
}
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/funnywuss/jenkins-test.git
git@gitee.com:funnywuss/jenkins-test.git
funnywuss
jenkins-test
jenkins-test
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385