我正在建立一个Azure DevOps项目来更新我们的网站。
我建立了一个测试网站,并使所有网站正常工作,以便每当我执行Git Push时它都会自动发布。
我遇到的问题是测试网站有2个文件,而真正的网站有2个文件,总大小超过500MB。
我希望有一种方法可以使它只推送更改过的文件,而不是每个单独的文件。
我的构建管道正在使用以下脚本:
Coin:integerTolerance
integerTolerance has value 1e-006
发布管道正在执行IIS Web App部署。
答案 0 :(得分:1)
我们确实遇到了同样的问题,不得不检查 Stackoverflow 和 Google 上的一些解决方案,最终制定了以下解决方案,这帮助我们仅选择基于 GIT 的最后修改的文件,然后仅发布这些文件而不是推送全部。
# HTML
# Archive your static HTML project and save it with the build record.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
# Updated to pick only modified files and push them for publish by adding "task: PowerShell" (to optimize CICD process)
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
#We fist check the latest modified files based on GIT DIFF command
#Then we loop through the files using files-split
#Next we split the file URL to get the file name and parent folder structure of the file separately
#Based on the file path, we check the path in output directory and create it if its not present
#Once the folder structure is available in the destination, we then copy the file to that location using copy-item command
#Force parameter is used copy-item to overwrite any existing files
script: $files=$(git diff HEAD HEAD~ --name-only);
$temp=$files-split ' ';
$count=$temp.Length;
echo "Total changed $count files";
For ($i=0; $i -lt $temp.Length; $i++)
{
$name=$temp[$i];
echo "Modified File - $name file";
$filepath = ($name.Split('/'))[0..($name.Split('/').count-2)] -join '/';
echo "File path - $filepath";
$destFile = Join-Path $(Build.ArtifactStagingDirectory) $name;
$destinationpath = Split-Path $destFile ;
echo "Destination path - $destinationpath";
if (!(Test-Path -Path $destinationpath)) {
New-Item $destinationpath -ItemType Directory
}
Copy-Item $name -Destination $destFile -Recurse -Force
}
Get-ChildItem -Path $(Build.ArtifactStagingDirectory) -Recurse -Force
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
- task: PublishBuildArtifacts@1
请注意,上面的代码工作得很好,由于每行开头的制表符/空格只能复制粘贴,我们需要在实际运行构建之前验证代码。
快乐编码..!
答案 1 :(得分:0)
仅使用管道释放更改的文件
没有这样一种即用型方法,只能在使用copy
任务或PublishBuildArtifacts
时选择修改后的文件。
作为解决方法,我们可以添加powershell任务来删除时间戳为<(现在-x分钟)的所有文件(递归),从而使Artifact目录仅包含已更改的文件。
在此处查看详细信息:TFS 2017 - how build/deliver only changed files?。
我尝试使用la脚的PowerShell技术开发此脚本,但未成功。
希望这会有所帮助。
答案 2 :(得分:0)
我能够根据该线程中另一个答案的建议来创建ADO powershell任务。
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'get-childitem $(build.artifactStagingDirectory) -recurse | Foreach {
$lastupdatetime=$_.LastWriteTime;
$nowtime=get-date;
if(($nowtime - $lastupdatetime).totalhours -le 24) {
Write-Host $_.fullname
}
else{
remove-item $_.fullname -Recurse -Force
}
}'
failOnStderr: true
workingDirectory: '$(build.artifactStagingDirectory)'
任务的脚本部分应该在一行中,但我对其进行了扩展以便于阅读。