You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline:确保空changedfiles文件夹纳入drop工件避免复制报错

解决Azure构建/发布管道中空文件夹缺失的问题

1. 修正PowerShell脚本,确保文件夹必创建+处理文件排除

把创建文件夹的逻辑独立出来强制执行,同时排除yml文件复制,最后为空文件夹添加占位文件(保证能被纳入构建工件):

# 强制创建changedfiles文件夹,无论是否有文件要复制
New-Item -ItemType Directory -Path "$(Build.ArtifactStagingDirectory)\changedfiles" -Force

# 仅当存在目标文件时,复制并排除所有yml文件
if ($file) {
    Copy-Item -Path $file -Destination "$(Build.ArtifactStagingDirectory)\changedfiles" -Exclude "*.yml"
}

# 检查文件夹是否为空,为空则生成占位文件
$targetFolder = "$(Build.ArtifactStagingDirectory)\changedfiles"
if (-not (Get-ChildItem -Path $targetFolder -Force)) {
    New-Item -ItemType File -Path "$targetFolder\.gitkeep" -Force
}

2. 确保发布任务包含该文件夹

如果使用Publish Build Artifacts任务,可勾选「Include empty directories」选项(部分版本任务支持)。不过更稳妥的是依赖上面的占位文件——只要文件夹内有文件(哪怕是.gitkeep),发布任务就会自动将文件夹纳入drop工件,无需额外配置。

3. 调整发布管道的复制逻辑

发布管道中的复制任务,可将源路径设置为$(System.ArtifactsDirectory)\drop\changedfiles\*,这样即使只有占位文件,也能正常执行复制,不会因文件夹不存在报错。如果不需要保留占位文件,可在复制后添加一个PowerShell步骤删除:

Remove-Item -Path "$(目标服务器路径)\changedfiles\.gitkeep" -Force -ErrorAction SilentlyContinue

内容的提问来源于stack exchange,提问作者Aizen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 16:20:35