Skip to content

Docker Executor on Windows does not fail jobs properly

Summary

Docker Executor on Windows always marks a job succeeded, even when PowerShell script ErrorActionPreference is set to Stop, or -ErrorAction Stop is used on a cmdlet. Shell Executor acts appropriately.

Only an explicit Exit 1 can mark the job as failed. This functionality is different than Shell Executor, where every job in this example fails as expected!

Steps to reproduce

Run any job with PowerShell script that stops the PowerShell script in the PowerShell way, using the docker-windows executor instead of the shell executor.

.gitlab-ci.yml
stages:
  - deploy

image: "mcr.microsoft.com/windows/servercore:10.0.17763.678"    # 2019-08-13

variables:
  ErrorActionPreference: 'Stop'
  
error-implicit-global:
  stage: deploy
  script:
    - Write-Error "Yo dawg, i heard you like errors"
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest

error-implicit-local:
  stage: deploy
  variables:
    ErrorActionPreference: 'Stop'
  script:
    - Write-Error "Yo dawg, i heard you like errors"
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest

error-implicit-script-var:
  stage: deploy
  script:
    - $ErrorActionPreference = 'Stop'
    - Write-Error "Yo dawg, i heard you like errors"
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest

error-explicit:
  stage: deploy
  variables:
    ErrorActionPreference: 'Stop'
  script:
    - Write-Error "Yo dawg, i heard you like errors" -ErrorAction Stop
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest
    
error-implicit-global-plus-linux-exit-after-error:
  stage: deploy
  script:
    - Write-Error "Yo dawg, i heard you like only LINUX errors"
    - Exit 4
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest
    
error-implicit-global-plus-linux-exit:
  stage: deploy
  script:
    - Write-Host 'Just doing Exit by itself'
    - Exit 4
    - Write-Host "this happened after the Write-Error but you will not see this message"
  tags:
    - windows-brett-glrtest

Actual behavior

The only job that is marked failed is the one with the explicit Exit 4 prior to any Write-Error statements.

Expected behavior

Every one of these 6 jobs should be marked as failed.

Used GitLab Runner version

Running with gitlab-runner 12.2.0 (a987417a)
Using Docker executor with image mcr.microsoft.com/windows/servercore:10.0.17763.678 

Have tested with 12.0.0, 12.0.1, 12.1.0 and 12.2.0 of the Docker Executor on Windows, they all have this problem.