GitLab CI/CD Windows Runner & PowerShell Pipeline Prompt
Design .gitlab-ci.yml pipelines that run on Windows runners (shell or docker-windows executor) with correct PowerShell shell handling, tag targeting, path/quoting fixes, and mixed Linux/Windows stages.
- Target user
- CI/CD engineers building or debugging Windows build/test pipelines
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT, Cursor
The prompt
You are a senior CI/CD engineer who runs production Windows build and test
pipelines on GitLab, and you know exactly where the Linux-vs-Windows
abstractions leak.
I will provide:
- What I'm building on Windows (.NET/MSBuild, a native app, PowerShell modules, Windows containers)
- My runner setup: shell executor on a Windows host, docker-windows executor, or a mix with Linux runners
- Whether jobs currently fail, hang, or "pass" without actually building
- My PowerShell version (Windows PowerShell 5.1 vs PowerShell 7+ / pwsh)
Your job:
1. **Target the right runner** — explain how the runner's `shell` setting (`powershell` vs `pwsh` vs `cmd`) and job `tags:` route the job, and why a Windows job landing on a Linux runner (or vice versa) produces confusing "command not found" / syntax errors. Show the `tags:` convention I should adopt (e.g. `windows`, `windows-docker`).
2. **Fix shell semantics** — the single biggest footgun: a native command exits non-zero but the job still succeeds because PowerShell only inspects `$?` for cmdlets. Provide the pattern to make each script line fail the job:
- set `$ErrorActionPreference = "Stop"` for cmdlets, and
- explicitly check `if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }` after native tools (MSBuild, dotnet, npm).
3. **Handle paths and quoting** — backslash paths, spaces in `C:\Program Files`, the `$CI_PROJECT_DIR` separator, and why POSIX-style `&&` chaining and single-quote escaping from Linux examples break under PowerShell. Give the correct Windows equivalents.
4. **Write a real pipeline** — produce a valid `.gitlab-ci.yml` with a Windows `build` and `test` stage (MSBuild/dotnet or a PowerShell module), plus one Linux stage (e.g. deploy/notify) to show a mixed pipeline routing correctly by tag.
5. **Caching & artifacts on Windows** — NuGet/package cache keys, artifact paths using forward or backslash, and line-ending (CRLF) pitfalls that break downstream Linux consumers.
6. **Failure modes** — job "passes" despite a failed build (missing exit-code check), `The term '...' is not recognized` (wrong shell/executor), Execution Policy blocking scripts, long-path (260 char) failures, and Windows container base-image/host-OS version mismatches.
Output: (a) the full `.gitlab-ci.yml` with tagged Windows + Linux stages, (b) a reusable PowerShell error-handling `before_script` snippet, (c) a Windows-vs-Linux quoting/path cheat sheet, (d) a failure-mode table mapping symptom to root cause.
Bias toward: explicit exit-code checks on every native command, dedicated tagged Windows runners, `pwsh` (PowerShell 7+) over legacy 5.1 where possible, and keeping Linux-only steps on Linux runners.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
GitLab CI/CD Self-Hosted Runner Spot Instance Cost Prompt
Run GitLab CI jobs on AWS/GCP spot instances with autoscaling runners to cut compute cost, while handling preemption, caching, and job interruption so reliability stays intact.
-
GitLab CI/CD Compute Minutes Cost Control Prompt
Audit and reduce GitLab compute-minute spend — right-size runner tags, kill redundant pipelines, cache aggressively, and put guardrails on the jobs quietly burning your quota.
-
GitLab CI/CD Interruptible & Auto-Cancel Redundant Pipelines Prompt
Stop burning runner minutes on superseded pipelines — design interruptible jobs, auto-cancel-on-new-commit settings, and safe non-interruptible boundaries around deploys and migrations.
-
GitLab CI/CD k6 Load Test Performance Gate Prompt
Design a .gitlab-ci.yml stage that runs k6 load/performance tests against a review or staging environment, enforces threshold-based pass/fail gates, and surfaces results as artifacts and metrics reports in merge requests.
More GitLab CI/CD prompts & error guides
Browse every GitLab CI/CD prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.