ci: add Jenkinsfile (build+push Harbor)
This commit is contained in:
parent
02035a1574
commit
ab6c6829c6
52
Jenkinsfile
vendored
Normal file
52
Jenkinsfile
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
// BuildFlow API CI/CD (.NET 10)
|
||||
// Checkout -> Build Image -> Push Harbor
|
||||
// 部署阶段预留: API 依赖 PG/Mongo/Redis/RabbitMQ, 待中间件就绪后启用 Deploy stage
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
HARBOR = "43.134.235.58:58080"
|
||||
IMAGE = "${HARBOR}/buildflow/buildflow-api"
|
||||
TAG = "${env.BUILD_NUMBER}"
|
||||
}
|
||||
options {
|
||||
timeout(time: 30, unit: "MINUTES")
|
||||
buildDiscarder(logRotator(numToKeepStr: "10"))
|
||||
}
|
||||
stages {
|
||||
stage("Checkout") {
|
||||
steps { checkout scm }
|
||||
}
|
||||
stage("Build Image") {
|
||||
steps {
|
||||
sh "docker build -t ${IMAGE}:${TAG} -t ${IMAGE}:latest ."
|
||||
}
|
||||
}
|
||||
stage("Push Harbor") {
|
||||
steps {
|
||||
withCredentials([usernamePassword(credentialsId: "harbor-credentials", usernameVariable: "HUSER", passwordVariable: "HPASS")]) {
|
||||
sh """
|
||||
echo \$HPASS | docker login ${HARBOR} -u \$HUSER --password-stdin
|
||||
docker push ${IMAGE}:${TAG}
|
||||
docker push ${IMAGE}:latest
|
||||
docker logout ${HARBOR}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
stage("Deploy") {
|
||||
// TODO: 等 PG/Mongo/Redis/RabbitMQ 中间件就绪后启用
|
||||
// 由 deploy-agent 节点执行: docker pull + docker compose up
|
||||
steps {
|
||||
echo "Deploy stage 暂未启用: API 依赖中间件(PG/Mongo/Redis/RabbitMQ)尚未部署"
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success { echo "BuildFlow API CI/CD SUCCESS: ${IMAGE}:${TAG}" }
|
||||
failure { echo "BuildFlow API CI/CD FAILED" }
|
||||
always {
|
||||
sh "docker rmi ${IMAGE}:${TAG} ${IMAGE}:latest 2>/dev/null || true"
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user