GitLab CI使用if语句的语法是什么

时间:2016-11-16 12:50:44

标签: if-statement syntax gitlab-ci

我想在构建脚本中检查我的一个变量的值,以便仅在变量具有特定值时进行部署。

deploy utilities:
  stage: deploy
  script:
    - echo %DEPLOY%
    - if [ "%DEPLOY%" == "utilities" ]; then 'msbuild.exe Build\TCBuild.CreateAndPublishNugetPackages.Utilities.Targets /p:BUILD_NUMBER=%CI_BUILD_ID%'; fi
  dependencies:
    - restore deploy packages
    - build utilities
  only: 
    - triggers
  artifacts:
    name: 'Utilities_nuget-package%CI_BUILD_ID%'
    expire_in: 1 days
    paths: 
    - Build

但是当它构建时,我收到以下错误:

"utilities" was unexpected at this time.

在.gitlab-ci.yml中使用if语句的正确语法是什么?

1 个答案:

答案 0 :(得分:1)

我的跑步者正在使用Windows CMD,因此语法错误。

正确的语法是:

IF "%DEPLOY%" == "utilities" msbuild.exe Build\TCBuild.CreateAndPublishNugetPackages.Utilities.Targets /p:BUILD_NUMBER=%CI_BUILD_ID%