What is the correct syntax for ci stage with multiple shell commands?

Given this example .Net CI pipeline configuration

image: mcr.microsoft.com/dotnet/sdk:5.0

stages:
  - build

build:
  stage: build
  script:
      - |
        BUILD_WARNINGS_LOG_FILE="buildWarnings.log";
        
        dotnet build -consoleloggerparameters:"Summary;Verbosity=normal" -m -p:"WarnLevel=5;EnforceCodeStyleInBuild=true" -t:"clean,build" -fl1 "/flp1:logFile=$BUILD_WARNINGS_LOG_FILE;warningsonly";
        
        if [ $? -eq 0 ] && [ $(wc -l < $BUILD_WARNINGS_LOG_FILE) -gt 0 ]
        then
          # do stuff here
        fi

The pipeline fails because of invalid syntax. I think this is because it doesn’t know there are multiple shell commands to execute.

This .sh file works on my local machine

#!/bin/bash

BUILD_WARNINGS_LOG_FILE="buildWarnings.log";

dotnet build --output build -consoleloggerparameters:"Summary;Verbosity=normal" -m -p:"WarnLevel=5;EnforceCodeStyleInBuild=true" -t:"clean,build" -fl1 "/flp1:logFile=$BUILD_WARNINGS_LOG_FILE;warningsonly";

if [ $? -eq 0 ] && [ $(wc -l < $BUILD_WARNINGS_LOG_FILE) -gt 0 ]
then
  # do stuff here
fi

so how can I embed it into a ci stage correctly?

Hi,

i check your code and the gitlabci seems to be valid. But on script, i see conditions and i would advice you to write your code in a script, that you call in your gitlabci file, like this :

image: mcr.microsoft.com/dotnet/sdk:5.0

stages:
  - build

build:
  stage: build
  script:
      - my-script.ksh
1 Like