Script sections mysteriously vanish while using Powershell Core
Summary
Powershell script sections mysteriously disappear. At first I thought this was related to backticks, but removing the backticks doesn't actually solve the problem.
Steps to reproduce
.gitlab-ci.yml
build vs2022 ltsc2022:
tags: ["windows-server-2022", "windows-shell", "x86_64"]
stage: build
rules:
- if: '$CI_DEFAULT_BRANCH == $CI_COMMIT_BRANCH'
variables:
TAG: ltsc2022
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
TAG: ltsc2022-merge-request-$CI_MERGE_REQUEST_IID
variables:
BASE_IMAGE_TAG: windowsservercore-ltsc2022
IMAGE: windows/vs2022
artifacts:
paths:
- build_info/build_*.json
interruptible: true
before_script:
- |
echo "$ARTIFACTORY_ACCESS_TOKEN" |
docker login "$CONTAINER_REGISTRY" --username "$ARTIFACTORY_USER" --password-stdin
script:
- Write-Output 'Hello World!'
- |
docker build . --build-arg BASE_IMAGE_TAG=windowsservercore-ltsc2022 --file Containerfile --memory 8GB --no-cache --pull --rm --tag "${IMAGE}:$TAG"
if(!$?) { Exit $LASTEXITCODE }
docker run --rm --volume "$Env:CI_PROJECT_DIR/test:c:/src/test" --workdir c:/src/test "${IMAGE}:$TAG" "c:/src/test/test.ps1"
if(!$?) { Exit $LASTEXITCODE }
if ( $Env:CI_DEFAULT_BRANCH -eq $Env:CI_COMMIT_BRANCH ) {
docker tag "${IMAGE}:$TAG" "$CONTAINER_REGISTRY/${IMAGE}:$TAG"
if(!$?) { Exit $LASTEXITCODE }
$publish_container_modules += ConvertFrom-Json @"
[{
"image": "${IMAGE}:$TAG",
"repository": "$CONTAINER_REGISTRY",
"properties": {},
"image-dependencies": [{
image: "powershell:$BASE_IMAGE_TAG",
repository: "microsoft-container-registry"
}],
"dependencies": []
}]
"@
Set-Content -Path "publish_container_modules.json" -Value (ConvertTo-Json -Depth 9 $publish_container_modules)
nu -c "use artifactory-build-info.nu; artifactory-build-info publish container modules $env:CI_PROJECT_NAME $env:CI_PIPELINE_IID"
if(!$?) { Exit $LASTEXITCODE }
}
after_script:
- docker container prune --force
- |
if ( $Env:CI_PIPELINE_SOURCE -eq "merge_request_event" ) {
docker image rm --force ${IMAGE}:$TAG
}
- docker image prune --force
Actual behavior
Notice the line Executing "step_script" stage of the job script 00:01 which indicates that nothing actually happens there.
The after_script which does not have backtick line breaks runs correctly.
...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:01
Running after_script 00:02
Running after script...
$ docker container prune --force
Total reclaimed space: 0B
...
Job succeeded
Expected behavior
I would expect the script section to actually run, or at least some of it, or to receive some sort of a parser error or some other error.
Relevant logs and/or screenshots
job log
Running with gitlab-runner 16.0.1 (79704081)
on Windows Server 2022 Shell xxxxx, system ID: xxxxx
feature flags: FF_ENABLE_JOB_CLEANUP:true
Resolving secrets 00:00
Preparing the "shell" executor 00:00
Using Shell (pwsh) executor...
Preparing environment 00:01
Running on CIBUILD-W01...
Getting source from Git repository 00:03
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in D:/gitlab-runner/builds/xxxx/0/org/visual-studio-container-image/.git/
Created fresh repository.
Checking out 7b4806a0 as detached HEAD (ref is refs/merge-requests/7/head)...
git-lfs/3.3.0 (GitHub; windows amd64; go 1.19.3; git 77deabdf)
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:01
Running after_script 00:02
Running after script...
$ docker container prune --force
Total reclaimed space: 0B
$ if ( $Env:CI_PIPELINE_SOURCE -eq "merge_request_event" ) { # collapsed multi-line command
Error response from daemon: No such image: windows/vs2022:ltsc2022-merge-request-7
$ docker image prune --force
Total reclaimed space: 0B
Uploading artifacts for successful job 00:01
Version: 16.0.1
Git revision: 79704081
Git branch: 16-0-stable
GO version: go1.19.9
Built: 2023-05-23T22:22:28+0000
OS/Arch: windows/amd64
Uploading artifacts...
Runtime platform arch=amd64 os=windows pid=16748 revision=79704081 version=16.0.1
WARNING: build_info/build_*.json: no matching files. Ensure that the artifact path is relative to the working directory (D:\gitlab-runner\builds\zxV8Psr7\0\hotswop\visual-studio-container-image)
ERROR: No files to upload
Cleaning up project directory and file based variables 00:01
HEAD is now at 7b4806a Add debug output
Job succeeded
Environment description
GitLab Runner using the Shell Executor with Powershell Core 7.3.4 on Windows Server 2022. The same issue occurs on a similarly configured runner on Windows Server 2019.
config.toml contents
concurrent = 15
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Windows Server"
request_concurrency = 15
url = "http://gitlab.org.com/"
id = 0
token = "xxxx"
token_obtained_at = 0001-01-01T00:00:00Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker-windows"
shell = "pwsh"
pre_build_script = "$ErrorActionPreference = 'Stop'"
builds_dir = "D:/gitlab-runner/builds"
cache_dir = "D:/gitlab-runner/cache"
environment = ["FF_USE_POWERSHELL_PATH_RESOLVER=1", "FF_DISABLE_POWERSHELL_STDIN=1", "FF_SCRIPT_SECTIONS=1"]
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "artifactory.org.com/container/windows/vs2022:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["D:/gitlab-runner/docker-cache"]
shm_size = 0
memory = "6g"
[[runners]]
concurrent = 1
name = "Windows Server 2022 Shell"
url = "http://gitlab.org.com"
id = 41
token = "xxxx-X-xxxx"
token_obtained_at = 2023-05-31T20:11:18Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "shell"
shell = "pwsh"
pre_build_script = "$ErrorActionPreference = 'Stop'"
builds_dir = "D:/gitlab-runner/builds"
cache_dir = "D:/gitlab-runner/cache"
environment = ["FF_ENABLE_JOB_CLEANUP=1"]
[runners.cache]
MaxUploadedArchiveSize = 0
Used GitLab Runner version
Version: 16.0.1
Git revision: 79704081
Git branch: 16-0-stable
GO version: go1.19.9
Built: 2023-05-23T22:22:28+0000
OS/Arch: windows/amd64
Possible fixes
Edited by Jordan Williams