我正在使用 Jenkins POD 进行部署。
流水线脚本:
pipeline {
agent {
kubernetes {
label 'helm-pod'
serviceAccount 'jenkins-helm'
containerTemplate {
name 'helm'
image 'wardviaene/helm-s3'
ttyEnabled true
command 'cat'
}
}
}
stages {
stage('Run helm') {
steps {
container('helm') {
dir('my-app'){
git url: 'git@github.com:myrepo/my-app.git', branch: 'master', credentialsId: 'CREDENTIAL_ID'
}
sh '''
HELM_BUCKET=helm-repo-dev.my-app.k8s.local
PACKAGE=myservichart
NAME_OVERRIDE=my-app
ENV_OVERRIDE_FILE_PATH=my-project/helm-service-override/app-app.prod.values.yaml
export AWS_REGION=eu-west-2
cp -r /home/helm/.helm ~
helm repo add metaservichart s3://${HELM_BUCKET}/charts
IS_DEPLOYED=$(helm list |grep -E "^${NAME_OVERRIDE}" |grep DEPLOYED |wc -l| tr -s " ")
if [ ${IS_DEPLOYED} == 0 ] ; then
helm install --name ${NAME_OVERRIDE} -f ${VALUE_OVERRIDE_FILE_PATH} metaservichart/${PACKAGE}
else
helm upgrade ${NAME_OVERRIDE} -f ${VALUE_OVERRIDE_FILE_PATH} metaservichart/${PACKAGE}
fi
echo "deployed!"
'''
}
}
}
}
}
CREDENTIAL_ID:在 Jenkins 中添加 github credendtails 并复制生成的 id。
ENV_OVERRIDE_FILE_PATH:环境特定的属性文件。
HELM_BUCKET:掌舵 s3 桶
NAME_OVERRIDE:要传递给 helm 的名称