2024-04-03 15:34:47 +08:00
|
|
|
/* groovylint-disable NestedBlockDepth */
|
|
|
|
// Description: Jenkinsfile for finance_dbt
|
|
|
|
|
|
|
|
pipeline {
|
|
|
|
agent {
|
|
|
|
kubernetes {
|
2024-04-08 11:32:59 +08:00
|
|
|
inheritFrom 'kaniko'
|
2024-04-03 15:34:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
environment {
|
|
|
|
DESTINATION_MACHINE = 'shennan@physical-ubuntu-server'
|
|
|
|
ORG = 'mujiannan'
|
|
|
|
PROJECT = 'finance-dbt'
|
|
|
|
DOCKER_REGISTRY = 'docker-registry.mujiannan.com:5001'
|
|
|
|
SMS_URL = 'https://nas.mujiannan.com:5001/webapi/entry.cgi?api=SYNO.Chat.External&method=incoming&version=2&token=%22XO8yFQyi66SStEPY7AALimGbNjMsZE85i3m0UlF0siIQtyn1deqSomp0CUheOwlE%22' // NOSONAR
|
|
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Pre Check') {
|
|
|
|
steps {
|
|
|
|
script {
|
|
|
|
// Retrieve the latest commit message
|
|
|
|
def String commitMessage = sh(returnStdout: 'true', script: 'git log -1 --pretty=%B').trim()
|
|
|
|
echo "Commit message: ${commitMessage}"
|
|
|
|
// Set a flag based on the commit message
|
|
|
|
if (commitMessage.contains('[SKIP CI]')) {
|
|
|
|
env.SKIP_CI = 'true'
|
|
|
|
}
|
|
|
|
// Set a flag based on the commit message
|
|
|
|
if (
|
|
|
|
commitMessage.contains('[SKIP CD]') || env.SKIP_CI == 'true' || (
|
|
|
|
env.BRANCH_NAME != 'dev' && env.BRANCH_NAME != 'test' && env.BRANCH_NAME != 'prod'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
env.SKIP_CD = 'true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
script {
|
|
|
|
// Set the image tag, GIT_TAG is preferred, if not available, use the commit hash abbreviated
|
|
|
|
env.IMAGE_TAG = sh(returnStdout: 'true', script: 'git describe --tags --always').trim()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Build') {
|
|
|
|
when {
|
|
|
|
not {
|
|
|
|
expression {
|
|
|
|
return env.SKIP_CI == 'true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-04-08 11:28:55 +08:00
|
|
|
steps {
|
|
|
|
container('kaniko') {
|
2024-04-03 15:34:47 +08:00
|
|
|
// Build the Docker image
|
|
|
|
sh """
|
|
|
|
/kaniko/executor \
|
|
|
|
--context . \
|
|
|
|
--cache=true \
|
|
|
|
--cache-dir="${WORKSPACE}/kaniko-cache" \
|
|
|
|
--registry-mirror="${DOCKER_REGISTRY}" \
|
|
|
|
--destination "${DOCKER_REGISTRY}:/${PROJECT}:${IMAGE_TAG}" \
|
|
|
|
--label org.opencontainers.image.branch=${BRANCH_NAME} \
|
2024-04-07 19:19:56 +08:00
|
|
|
--label org.opencontainers.image.build_tag=${BUILD_TAG} \
|
2024-04-03 15:34:47 +08:00
|
|
|
--label org.opencontainers.image.revision="${GIT_COMMIT}" \
|
2024-04-08 11:22:27 +08:00
|
|
|
--label org.opencontainers.image.version="${IMAGE_TAG}" \
|
2024-04-03 15:34:47 +08:00
|
|
|
--label org.opencontainers.image.url="${BUILD_URL}" \
|
|
|
|
--label org.opencontainers.image.source="${GIT_URL}"
|
|
|
|
"""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stage('Deploy') {
|
|
|
|
when {
|
|
|
|
not {
|
|
|
|
expression {
|
|
|
|
return env.SKIP_CD == 'true'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
steps {
|
|
|
|
withKubeConfig([namespace: "${BRANCH_NAME}"]) {
|
|
|
|
container('kubectl') {
|
|
|
|
sh '''
|
|
|
|
export deployment=$BRANCH_NAME
|
|
|
|
export namespace=$BRANCH_NAME
|
|
|
|
export image_tag=$IMAGE_TAG
|
|
|
|
kubectl apply -f Deploy.yml
|
|
|
|
kubectl rollout restart deployment finance-dbt-doc
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|