gpt4 book ai didi

azure-devops - 使用 Pipelines 仅发布更改的文件

转载 作者:行者123 更新时间:2023-12-01 21:55:50 26 4
gpt4 key购买 nike

我正在努力建立一个 Azure DevOps 项目来更新我们的网站。
我建立了一个测试网站,并使其全部正常运行,以便在我执行 Git Push 时它会自动发布。

我遇到的问题是测试网站有 2 个文件,而真实网站有更多文件,总计超过 500MB。

我希望有一种方法可以让它只推出更改的文件,而不是每个文件。

我的构建管道使用以下脚本:

trigger:
- master

pool:
vmImage: 'ubuntu-latest'

steps:

- task: ArchiveFiles@2
displayName: 'ArchiveFiles'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false

- task: PublishBuildArtifacts@1
displayName: 'Publish Artifacts: drop'

发布管道正在执行 IIS Web 应用程序部署。

最佳答案

我们确实遇到了同样的问题,不得不在 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

请注意,上面的代码工作得很好,由于每行开头的制表符/空格,只能复制粘贴,我们需要在实际运行构建之前验证代码。

编码愉快..!

关于azure-devops - 使用 Pipelines 仅发布更改的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57296902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com