能否使用特定于分支的变量重用gitlab CI脚本?

能否使用特定于分支的变量重用gitlab CI脚本?,gitlab,gitlab-ci,gitlab-ci-runner,gitlab-ce,Gitlab,Gitlab Ci,Gitlab Ci Runner,Gitlab Ce,我有一个gitlab CI脚本,它使用Web服务器上的运行程序部署网站。有多个部署(取决于分支上的AO)。除了从文件复制到的htdocs目录外,脚本始终相同 stages: - build - deploy pages: stage: build script: - hugo artifacts: paths: - public/ deploy_to_test: stage: deploy tags: - web-deploy sc

我有一个gitlab CI脚本,它使用Web服务器上的运行程序部署网站。有多个部署(取决于分支上的AO)。除了从文件复制到的htdocs目录外,脚本始终相同

stages:
  - build
  - deploy

pages:
  stage: build
  script:
  - hugo
  artifacts:
    paths:
    - public/

deploy_to_test:
  stage: deploy
  tags:
    - web-deploy
  script:
    - rsync -av --omit-dir-times --no-owner --delete public/ /var/www/wwwtest.my/
    - find /var/www/wwwtest.my/ -type f -exec chmod 644 {} \;
    - find /var/www/wwwtest.my/ -type d -exec chmod 755 {} \;
  environment:
    name: test
  only:
    - develop


deploy_to_prod:
  stage: deploy
  tags:
    - web-deploy
  script:
    - rsync -av --omit-dir-times --no-owner --delete public/ /var/www/www.my/
    - find /var/www/www.my/ -type f -exec chmod 644 {} \;
    - find /var/www/www.my/ -type d -exec chmod 755 {} \;
  environment:
    name: prod
  only:
    - master

是否有可能遵循DRY原则,将htdocs目录设置为分支因变量并重用部署脚本?

您可以定义一个YAML模板,以便跨作业重用。 每个作业都可以定义模板脚本可以使用的自定义变量

例如:

.template: &template
  stage: deploy
  tags:
    - web-deploy
  script:
    - **Use the $HTDOCS variable**

deploy_to_test:
  <<: *template
  environment:
    name: prod
  variables:
    - HTDOCS: foo
  only:
    - master
.template:&template
阶段:部署
标签:
-web部署
脚本:
-**使用$HTDOCS变量**
部署\u到\u测试:

你能给我一个关于这个语法的参考吗。我在gitlab文档和YAML规范中都找不到它。很抱歉没有提供参考:gitlab文档:另一篇文章: