feat: add branch strategy via BranchStrategy class

Stages now gated by branch:
- PR-*: test only
- feature/*: test + build/push + helm bump + git push
- develop/main/release/hotfix: test + build/push only
This commit is contained in:
2026-04-26 13:56:15 +07:00
parent 547c435694
commit 0d0ccf0e6e

66
Jenkinsfile vendored
View File

@@ -1,35 +1,15 @@
@Library('homelab') _
import vn.fireflylab.pipeline.BranchStrategy
pipeline {
agent {
kubernetes {
yaml """
apiVersion: v1
kind: Pod
spec:
containers:
- name: node
image: node:18-slim
command:
- sleep
args:
- infinity
- name: docker
image: docker:dind
securityContext:
privileged: true
env:
- name: DOCKER_TLS_CERTDIR
value: ""
args:
- --insecure-registry=harbor-core.harbor.svc.cluster.local
"""
yaml homelabK8sAgent(withTools: true)
}
}
environment {
APP_NAME = 'tictactoe'
HARBOR_REGISTRY = 'harbor-core.harbor.svc.cluster.local'
HARBOR_PROJECT = 'library'
IMAGE = "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${APP_NAME}"
DOCKER_HOST = 'tcp://localhost:2375'
}
@@ -37,28 +17,34 @@ spec:
stage('Install & Test') {
steps {
container('node') {
sh 'npm install'
sh 'npm test'
runNodeTest()
}
}
}
stage('Build & Push Image') {
when { expression { BranchStrategy.shouldBuildImage(env.BRANCH_NAME) } }
steps {
script {
def imageTag = "${env.BRANCH_NAME.replaceAll('/', '-')}-${UUID.randomUUID().toString().take(8)}"
container('docker') {
withCredentials([usernamePassword(
credentialsId: 'harbor-credentials',
usernameVariable: 'HARBOR_USER',
passwordVariable: 'HARBOR_PASS'
)]) {
sh """
docker login ${HARBOR_REGISTRY} -u \${HARBOR_USER} -p \${HARBOR_PASS}
docker build -t ${IMAGE}:${imageTag} .
docker push ${IMAGE}:${imageTag}
"""
}
script {
def tag = BranchStrategy.imageTag(env.BRANCH_NAME)
env.IMAGE_TAG = tag
dockerBuildPush(appName: 'tictactoe', tag: tag)
}
}
}
}
stage('Bump Helm Chart') {
when { expression { BranchStrategy.shouldBumpChart(env.BRANCH_NAME) } }
steps {
container('tools') {
script {
bumpHelmChart(imageTag: env.IMAGE_TAG)
gitCommitPush(
files: ['manifest/helm/Chart.yaml', 'manifest/helm/values.yaml'],
message: "ci: bump tictactoe chart to ${env.IMAGE_TAG}"
)
}
}
}