如何解决Gitlab使用if语句检查gitlab-ci.yml中图像版本是否为最新版本
我有多个项目,这些项目基本上只包含一个gitlab-ci.yml文件,用于安装舵图。
我希望能够更改文件中舵图的版本,然后提交并使其部署。但是我希望能够让gitlab检查该版本是否与当前安装的版本不同,或者甚至没有安装。
可以使用if语句吗? 这是我为一个项目准备的,这是为我的登台集群添加一个运行器,为我的生产集群添加一个运行器:
services:
- docker:18-dind
variables:
IMAGE-VERSION: "latest"
CHART-VERSION: "0.20.0"
DEPLOY-TYPE: "install"
stages:
- create-namespaces-staging
- deploy-staging
- create-namespaces-production
- deploy-production
create-namespaces-staging:
image:
name: "thorstenhans/helm3:$IMAGE-VERSION"
entrypoint: ["/bin/sh","-c"]
stage: create-namespaces-staging
environment:
name: staging
script:
- echo ${CI_JOB_NAME}
- helm version
- kubectl version
- cd deployments/
- if [ "$DEPLOY-TYPE" == "install" ]; then kubectl apply -f gitlab-namespaces.yml; fi
deploy-cluster-staging:
image:
name: thorstenhans/helm3:latest
entrypoint: ["/bin/sh","-c"]
stage: deploy-cluster-staging
environment:
name: staging
kubernetes:
namespace: gitlab
script:
- echo ${CI_JOB_NAME}
- helm version
- kubectl version
- cd deployments/
- helm repo add gitlab https://charts.gitlab.io/
- if [ "$DEPLOY-TYPE" == "install" ]; then helm install gitlab/gitlab-runner --version $CHART-VERSION -f values-cluster-staging.yml; fi
- if [ "$DEPLOY-TYPE" == "upgrade" ]; then helm upgrade gitlab/gitlab-runner --version $CHART-VERSION -f values-cluster-staging.yml; fi
- if [ "$DEPLOY-TYPE" == "uninstall" ]; then helm delete gitlab/gitlab-runner; fi
create-namespaces-production:
image:
name: "thorstenhans/helm3:$IMAGE-VERSION"
entrypoint: ["/bin/sh","-c"]
stage: create-namespaces-production
environment:
name: production
when: manual
script:
- echo ${CI_JOB_NAME}
- helm version
- kubectl version
- cd deployments/
- if [ "$DEPLOY-TYPE" == "install" ]; then kubectl apply -f gitlab-namespaces.yml; fi
deploy-cluster-production:
image:
name: thorstenhans/helm3:latest
entrypoint: ["/bin/sh","-c"]
stage: deploy-cluster-production
environment:
name: production
kubernetes:
namespace: gitlab
when: manual
script:
- echo ${CI_JOB_NAME}
- helm version
- kubectl version
- cd deployments/
- helm repo add gitlab https://charts.gitlab.io/
- if [ "$DEPLOY-TYPE" == "install" ]; then helm install gitlab/gitlab-runner --version $CHART-VERSION -f values-cluster-production.yml; fi
- if [ "$DEPLOY-TYPE" == "upgrade" ]; then helm upgrade gitlab/gitlab-runner --version $CHART-VERSION -f values-cluster-production.yml; fi
- if [ "$DEPLOY-TYPE" == "uninstall" ]; then helm delete gitlab/gitlab-runner; fi
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。