git - Kubernetes cronjob - git pull else git clone
问题描述
Kubernetes cronjob 可用于使用 git 存储库中的最新数据更新某些卷。
containers:
- name: hello
image: alpine/git
volumeMounts:
- name: requirements
mountPath: /workdir
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- cd /workdir/dashboard; git pull http://url..
但它还没有准备好从盒子里开始工作。如果卷为空,我需要先执行 git clone ,然后每次执行 git pull 。
但是由于某种原因,将 bash if 语句作为 cronjob 命令不起作用 - cronjob 只会失败。
if cd /workdir/dashboard; then git pull http://url..; else git clone http://url..; fi
日志是fatal: not a git repository (or any parent up to mount point /) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)
有谁知道如何使它工作?
解决方案
如果你想做一个 git pull 并且如果 repo 在本地不存在,你可以使用以下代码片段仅在第一个命令失败时执行第二个命令,即 repo 尚未克隆
git pull || git clone $git-repo-url
推荐阅读
- javascript - 带有平滑滚动效果的粘滞标题封面内容
- javascript - 使用 yyyy-mm-dd 格式查找数组中的最小和最大日期
- c - GTK 的非标准设备事件输入
- r - 在使用 dcast 重塑之前顺序重命名字符变量中的重复值
- javascript - photosphere viewer - 从 GPS lat-long 显示标记 lat-long
- python - 如何使用 pandas read_pickle 从 qrc 资源文件中读取包含 pandas 数据框的 pickle 文件?
- html - CSS -div 扩展为多行文本与单行文本
- bash - bash 认为这个参数是一个命令吗?
- visual-studio-2012 - 将堆积图与条形图相结合
- typescript - 数组元素上不存在属性