2

I would like to check the value of one of my variables in my build script in order to only deploy if a variable has a specific value.

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

But when it builds I get the following error:

"utilities" was unexpected at this time.

What is the correct syntax for using if statements in .gitlab-ci.yml?

1 Answer 1

1

My runner is using Windows CMD therefore the syntax was wrong.

The correct syntax is:

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.