贵阳业财模板

一、jenkins流水线模板:

pipeline{
agent any

environment {
CLEANED_BRANCH = "${params.BRANCH}".replace("/", "-")
BUILD_TAG = "${CLEANED_BRANCH}-${new Date().format('yyyyMMddHHmmssSSS')}-${env.BUILD_NUMBER}"
yamlTmp="/mnt/paas/jenkins/workspace/k8s_deploy/templete-uat-gateway-v1.yaml"
yamlFile="/mnt/paas/jenkins/workspace/k8s_deploy/${JOB_NAME}-dep-uat.yaml"
}

parameters {
gitParameter branchFilter: 'origin/(.*)', defaultValue: 'uat', name: 'BRANCH', type: 'PT_BRANCH'
}

stages {
stage('Checkout') {
steps{
//git branch -D "${params.BRANCH}"
git branch: "${params.BRANCH}", credentialsId: '00f48456-582d-4bb0-ae8b-35277ddfa078',url: "http://1.95.9.40:30080/yc-yth-backend/fdp-eh-gateway.git"
echo '---This is a Checkout step---'
}
}
stage('build code') {
steps{
sh "cd $WORKSPACE/"
//sh "/usr/local/maven/bin/mvn clean install -T 8C -Dmaven.test.skip=true -Dmaven.compile.fork=true"
sh "/usr/local/maven/bin/mvn clean deploy -U -T 8C -P uat -Dmaven.test.skip=true -Dmaven.compile.fork=true"
}
}

stage('build image') {
steps{
sh "docker build -t ${JOB_NAME}:${BUILD_TAG} -f docker/uat/Dockerfile ."
sh "docker tag ${JOB_NAME}:${BUILD_TAG} swr.cn-southwest-2.myhuaweicloud.com/yc-yth/${JOB_NAME}:${BUILD_TAG}"
sh "docker push swr.cn-southwest-2.myhuaweicloud.com/yc-yth/${JOB_NAME}:${BUILD_TAG}"
}
}

stage('Deploy') {
steps{
sh "/bin/cp -f ${yamlTmp} ${yamlFile}"
//sh "/bin/cp -rf /data/k8s_deploy/templete-uat-v1.yaml /data/k8s_deploy/${JOB_NAME}-dep.yaml"
sh "sed -i 's#SVC_NAME#${JOB_NAME}#g' ${yamlFile}"
sh "sed -i 's#RC_NUM#1#g' ${yamlFile}"
sh "sed -i 's#IMAGE_URL#swr.cn-southwest-2.myhuaweicloud.com/yc-yth/${JOB_NAME}:${BUILD_TAG}#g' ${yamlFile}"
sh "sed -i 's#CON_PORT#18080#g' ${yamlFile}"
sh "sed -i 's#CLU_PORT#18080#g' ${yamlFile}"
sh "sed -i 's#NODE_PORT#30122#g' ${yamlFile}"
// sh "sed -i '/nodeSelector:/{n;s/app: SVC_NAME/app: fdp-eh-gateway-uat/}' ${yamlFile}"
sh "kubectl apply -f ${yamlFile}"
echo "deploy success"
}
}
}
}

二、yaml模版:/mnt/paas/jenkins/workspace/k8s_deploy/templete-uat-gateway-v1.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
namespace: yc-uat
labels:
app: SVC_NAME
name: SVC_NAME
spec:
replicas: RC_NUM
selector:
matchLabels:
app: SVC_NAME
template:
metadata:
labels:
app: SVC_NAME
spec:
nodeSelector:
tagSel: uat-master
volumes:
#- name: nginx-logs
# hostPath:
# path: /mnt/paas/efk/logs/financials-web-yw/nginx
# type: DirectoryOrCreate
restartPolicy: Always
#hostNetwork: true
containers:
- name: SVC_NAME
image: IMAGE_URL
resources:
limits:
memory: 2048Mi
cpu: "1"
requests:
memory: 512Mi
cpu: "0.2"
imagePullPolicy: Always
# volumeMounts:
# - name: nginx-logs
# mountPath: /var/log/nginx

 

posted @ 2024-11-21 13:39  追梦boyaaa  阅读(2)  评论(0编辑  收藏  举报