沈楠
a3587389a8
Some checks failed
MJN/finance-dbt/pipeline/head There was a failure building this commit
100 lines
4.0 KiB
Groovy
100 lines
4.0 KiB
Groovy
/* groovylint-disable NestedBlockDepth */
|
|
// Description: Jenkinsfile for finance_dbt
|
|
|
|
pipeline {
|
|
agent {
|
|
kubernetes {
|
|
inheritFrom 'kaniko'
|
|
}
|
|
}
|
|
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.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'
|
|
}
|
|
}
|
|
}
|
|
steps {
|
|
container('kaniko') {
|
|
// Build the Docker image
|
|
sh """
|
|
/kaniko/executor \
|
|
--context . \
|
|
--cache=true \
|
|
--cache-dir="${WORKSPACE}/kaniko-cache" \
|
|
--registry-mirror="${DOCKER_REGISTRY}" \
|
|
--destination "${DOCKER_REGISTRY}/${ORG}/${PROJECT}:${IMAGE_TAG}" \
|
|
--label org.opencontainers.image.branch=${BRANCH_NAME} \
|
|
--label org.opencontainers.image.build_tag=${BUILD_TAG} \
|
|
--label org.opencontainers.image.revision="${GIT_COMMIT}" \
|
|
--label org.opencontainers.image.version="${IMAGE_TAG}" \
|
|
--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 '''
|
|
if {
|
|
[ "dev" = "$BRANCH_NAME" ] ||
|
|
[ "test" = "$BRANCH_NAME" ] ||
|
|
[ "prod" = "$BRANCH_NAME" ]
|
|
}; then
|
|
export deployment=$BRANCH_NAME
|
|
export namespace=$BRANCH_NAME
|
|
else
|
|
export deployment=dev
|
|
export namespace=dev
|
|
fi
|
|
export image_tag=$IMAGE_TAG
|
|
. ./Deploy.sh
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |