function Publish-Artifacts { [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$OutputDir, [Parameter(Mandatory = $true)] [ValidateSet("smb", "scp")] [string]$Mode ) if (-not (Test-Path -LiteralPath $OutputDir)) { throw "Output directory does not exist: $OutputDir" } switch ($Mode) { "smb" { if ([string]::IsNullOrWhiteSpace($env:DESTINATION_PATH)) { throw "DESTINATION_PATH is required for DEPLOY_MODE=smb" } New-Item -Path $env:DESTINATION_PATH -ItemType Directory -Force | Out-Null Copy-Item -Path (Join-Path $OutputDir "*") -Destination $env:DESTINATION_PATH -Recurse -Force Write-Host "Artifacts copied to SMB/local path: $($env:DESTINATION_PATH)" } "scp" { if ([string]::IsNullOrWhiteSpace($env:SCP_DESTINATION)) { throw "SCP_DESTINATION is required for DEPLOY_MODE=scp" } $scpCommand = Get-Command scp -ErrorAction SilentlyContinue if (-not $scpCommand) { throw "scp is not available on this runner. Install OpenSSH client or use DEPLOY_MODE=smb." } & scp -r (Join-Path $OutputDir "*") $env:SCP_DESTINATION if ($LASTEXITCODE -ne 0) { throw "scp publish failed with exit code $LASTEXITCODE" } Write-Host "Artifacts copied using SCP to: $($env:SCP_DESTINATION)" } } }