ci: fix Windows job flakiness caused by dirty workspace by Leiyks · Pull Request #3694 · DataDog/dd-trace-php

added 2 commits

March 11, 2026 15:55
The cmd.exe "for /d" loop used to clean the workspace skips directory
entries during deletion (enumerates and deletes in the same pass), leaving
artifact output dirs from previous runs. When git clone then fails because
the workspace isn't empty, $PSNativeCommandUseErrorActionPreference = $true
is silently ignored on Windows PowerShell 5.1 (requires PS 7.3+), so the
script continues without source code and phpize.bat fails with exit 10.

Fixes:
- Replace cmd.exe cleanup loop with PowerShell-native Get-ChildItem | Remove-Item
  which handles each entry independently and tolerates locked files
- Add WARNING log line if any items could not be removed (aids debugging)
- Remove $PSNativeCommandUseErrorActionPreference (no-op on PS 5.1)
- Add explicit $LASTEXITCODE checks after git clone, checkout, and submodule init

Applied to both generate-package.php (compile extension windows) and
generate-tracer.php (windows test_c).
… cleanup

PowerShell 5.1's Remove-Item -Recurse throws "mismatch between the tag
specified in the request and the tag present in the reparse point" when
the workspace contains Windows junction points (created by switch-php,
e.g. /php <<===>> /php-nts) or NTFS symlinks (from core.symlinks=true
git clone). This caused the entire cleanup to fail silently, leaving
the full previous repo tree in place and making git clone fail again.

Fix: navigate to the parent directory and run cmd.exe "rd /s /q" on
the whole workspace directory. cmd.exe rd removes junction entries
without following them into their targets, avoiding the reparse point
issue entirely. The directory is then recreated empty before returning.

@Leiyks

php_ddtrace.dll (and other workspace files) are locked with "Access is
denied" when a Docker container from a previous job run is still alive
with the workspace volume mounted. This causes rd /s /q to fail and
git clone to fail again.

Fix: force-remove all running containers (docker rm -f $(docker ps -aq))
before the rd /s /q workspace cleanup, releasing all file handles.

@Leiyks Leiyks changed the title ci: fix Windows workspace cleanup and fail-fast for git operations ci: fix Windows job flakiness caused by dirty workspace

Mar 12, 2026

@Leiyks

@Leiyks Leiyks marked this pull request as ready for review

March 12, 2026 14:48

@Leiyks

…leanup

Applies the same GIT_STRATEGY: none + manual clone pattern to the
verify windows job, saving/restoring the packages/ artifact around the
workspace cleanup to avoid git checkout failures on locked/junction files.

@Leiyks Leiyks deleted the leiyks/fix-windows-job-flakiness branch

March 17, 2026 13:14

bwoebi added a commit that referenced this pull request

Mar 20, 2026
…dd-update

* 'master' of github.com:DataDog/dd-trace-php:
  feat(sidecar): add thread mode as fallback connection for restricted environments (#3573)
  Migrate deprecated GitLab runner tags (#3715)
  Adds process tags to remote config payload (#3658)
  perf(config): cache sys getenv (#3670)
  Fixes the tag name for process tags (#3709)
  Fix debugger ephemerals handling (#3685)
  Fix #3651: Prevent crash during shutdown in Frankenphp (#3662)
  Add dynamic instrumentation and exception replay to startup logging (#3667)
  chore: bump bytes crate from 1.9.0 to 1.11.1 to address CVE-2026-25541 (#3669)
  Merge pull request #3701 from DataDog/brian.marks/add-ksr-tag
  ci: fix Windows job flakiness caused by dirty workspace (#3694)
  Fixup CI owner association (#3704)
  Add Rust rewrite of the AppSec helper alongside the C++ implementation
  Remove debug instruction
  Fix script order
  debug
  Fix exploration logic
  chore(ci): add final_status property on junit XML [APMSP-2610]
  Fix DD_TRACE_SYMFONY_HTTP_ROUTE=false
  Optimize Symfony http.route caching with path map approach