Running multi-line commands with powershell

Hi folks,

I’ve set up a runner on WIndows 10 with shell=powershell. In the gitlab-ci.yml I’m trying to invoke a command split over multiple lines. With powershell, you’re supposed to use the backtick (`) as the escape character, but it’s not working. For example, this build log, where the -G option is on a separate line, resulting in the error “Unexpected token ‘-G’ in expression or statement.”.

What’s the recommended way of doing multi-line commands in the YAML format? I thought the “- |” block I was using would be fine. Is there a better way to do things?

.win_configure: &win_configure
    - |
        $ErrorActionPreference = "Stop"
        cmd /c "call %VCVARSALL% & set" |
        foreach {
          if ($_ -match "=") {
            $v = $_.split("="); set-item -force -path "ENV:\$($v[0])"  -value "$($v[1])"
        git clean -dxf
        mkdir b
        cd b
        "$env:CMAKE" `
          -G "$env:BUILD_SYSTEM" `
          "-DCMAKE_BUILD_TYPE=$env:BUILD_TYPE" `
          "-DCMAKE_PREFIX_PATH:PATH=$env:CI_PROJECT_DIR/deps/dist" `
          "-Ddoxygen:BOOL=$env:BUILD_DOXYGEN" `
          "-Dextended-tests:BOOL=$env:BUILD_EXTENDED_TESTS" `
          "-Dsphinx:BOOL=$env:BUILD_SPHINX" `
          $env:DOXYGEN_TAGS `
          "-DGTEST_ROOT:PATH=$env:GTEST_ROOT" `

Thanks all,

Hi Roger, did you manage to find an answer to this? I was looking at a similar problem, where I wanted to run a python script formatted inside the .gitlab-ci.yml file, but had trouble due to indentation issues.

Hi Christoph,

No, I didn’t I’m afraid. I ended up splitting out most of the logic into separate scripts:

Not as nice, but it works. This way, it’s possible to run multiple scripts from a single script block, but it’s not possible to share the configuration between repositories like you can with gitlab configuration files (at least, as far as I know).

1 Like

Thanks for the example link - that’s pretty helpful!