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:
70
Jenkinsfile
vendored
70
Jenkinsfile
vendored
@@ -1,64 +1,50 @@
|
||||
@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'
|
||||
DOCKER_HOST = 'tcp://localhost:2375'
|
||||
}
|
||||
|
||||
stages {
|
||||
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}
|
||||
"""
|
||||
}
|
||||
container('docker') {
|
||||
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}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user