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 {
|
pipeline {
|
||||||
agent {
|
agent {
|
||||||
kubernetes {
|
kubernetes {
|
||||||
yaml """
|
yaml homelabK8sAgent(withTools: true)
|
||||||
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
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
APP_NAME = 'tictactoe'
|
DOCKER_HOST = 'tcp://localhost:2375'
|
||||||
HARBOR_REGISTRY = 'harbor-core.harbor.svc.cluster.local'
|
|
||||||
HARBOR_PROJECT = 'library'
|
|
||||||
IMAGE = "${HARBOR_REGISTRY}/${HARBOR_PROJECT}/${APP_NAME}"
|
|
||||||
DOCKER_HOST = 'tcp://localhost:2375'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Install & Test') {
|
stage('Install & Test') {
|
||||||
steps {
|
steps {
|
||||||
container('node') {
|
container('node') {
|
||||||
sh 'npm install'
|
runNodeTest()
|
||||||
sh 'npm test'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build & Push Image') {
|
stage('Build & Push Image') {
|
||||||
|
when { expression { BranchStrategy.shouldBuildImage(env.BRANCH_NAME) } }
|
||||||
steps {
|
steps {
|
||||||
script {
|
container('docker') {
|
||||||
def imageTag = "${env.BRANCH_NAME.replaceAll('/', '-')}-${UUID.randomUUID().toString().take(8)}"
|
script {
|
||||||
container('docker') {
|
def tag = BranchStrategy.imageTag(env.BRANCH_NAME)
|
||||||
withCredentials([usernamePassword(
|
env.IMAGE_TAG = tag
|
||||||
credentialsId: 'harbor-credentials',
|
dockerBuildPush(appName: 'tictactoe', tag: tag)
|
||||||
usernameVariable: 'HARBOR_USER',
|
}
|
||||||
passwordVariable: 'HARBOR_PASS'
|
}
|
||||||
)]) {
|
}
|
||||||
sh """
|
}
|
||||||
docker login ${HARBOR_REGISTRY} -u \${HARBOR_USER} -p \${HARBOR_PASS}
|
|
||||||
docker build -t ${IMAGE}:${imageTag} .
|
stage('Bump Helm Chart') {
|
||||||
docker push ${IMAGE}:${imageTag}
|
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