#stage执行流程
stages:
- update-global-nginx
- update-harbor-helm
- update-harbor-yaml
#全局变量定义
variables:
NAME: zhangsan
#全局镜像
image: docker:
image: bitnami/kubectl:latest
#执行stage前执行
before_script:
- echo ${KUBE_CONFIG} | base64 --decode > $HOME/.kube/config
#stage名称
update_nginx:
#对应上面的stages
stage: update-global-nginx
#执行命令
script:
- echo "===> 更新nginx的yaml..."
- set -x
- kubectl apply -f global-nginx/.
#触发条件
only:
changes: #只有文件global-nginx/*.yaml变动触发该stage
- global-nginx/*.yaml
refs: #只有dev分支变动触发改stage
- dev
update_harbor_helm:
#该stage使用镜像
image: nginx:latest
stage: update-harbor-helm
script:
- echo ""
- set -x
- kubectl version --short && echo $KUBE_CONFIG | base64 -d > $KUBECONFIG
- helm upgrade harbor -n harbor -f harbor/helm-bash/values.yaml harbor/helm-bash
only:
changes:
- harbor/helm-bash/**/*
if:
update_harbor_yaml:
stage: update-harbor-yaml
script:
- set -x
- kubectl version --short && echo $KUBE_CONFIG | base64 -d > $KUBECONFIG
- kubectl apply -f harbor/
environment:
name: production
only:
changes:
- harbor/helm-bash/*.yaml
need:
- update-harbor-yaml
when: on_success
#该tag局部变量
variables:
KUBECONFIG: '/home/gitlab-runner/.kube/config'
.gitlab-ci.yml
于 2024-02-04 15:09:04 首次发布