【发布时间】:2021-08-04 12:03:54
【问题描述】:
我想编写一个可从我们的全局构建模板中包含的模板,并将 repo 的静态文件夹复制到我的静态服务器。
全局构建模板(build.yml):
stages:
- test
- build
- deploy
include:
...
- local: '/ci-templates/publish_static.yml'
可以在所有 repos 中使用 (my-app/.gitlab-ci.yml):
include:
- project: 'mycompany/ci-tools'
file: '/ci-templates/build.yml'
鉴于回购结构:
my-app
│ .gitlab-ci.yml
└───myapp
└───static
规则类似于:
publish_static:
stage: deploy
script:
- export STATIC="$(find . -type d -name static)"
- rsync -rvv $STATIC deploy@static.server.com:/www/static
不幸的是,并非所有 repos 都有静态文件夹,我找不到使用 rules:exists 的方法,因为静态文件夹不在与 $CI_PROJECT_NAME 匹配的子文件夹中。
我尝试使用 bash 逻辑:
publish_static:
stage: deploy
script:
- export STATIC="$(find . -type d -name static)"
- '[ -d $STATIC ] && rsync -rvv $STATIC deploy@static.server.com:/www/static'
[ -d .. ] 失败时导致作业失败。
有没有办法使用我忽略的rules:exists? ..或者即使$STATIC 目录不存在,是否有办法使最后一个命令“成功”?
(我添加了allow_failure: true,但我们真的希望我们的管道上有全绿色的复选图标;-)
【问题讨论】:
-
not all repos have a static folder, and I can't find a way to use rules:exists since the static folder isn't in a subfolder that matches $CI_PROJECT_NAME.我不明白那部分。你是什么意思“子文件夹匹配$CI_PROJECT_NAME”?你想使用通配符吗? -
[ -d $STATIC ] && rsync... || true呢? -
@RenaudPacalet 可以工作:-)