Azure devops 仅释放带有管道的已更改文件

Azure devops 仅释放带有管道的已更改文件,azure-devops,azure-pipelines,Azure Devops,Azure Pipelines,我正在建立一个Azure DevOps项目来更新我们的网站。 我建立了一个测试网站,并让它正常工作,这样每当我推Git时,它就会自动发布 我遇到的问题是,测试网站有2个文件,而真正的网站有更多的文件,总数略高于500MB 我希望有一种方法可以让它只推出更改过的文件,而不是每个文件 我的生成管道正在使用以下脚本: trigger: - master pool: vmImage: 'ubuntu-latest' steps: - task: ArchiveFiles@2 display

我正在建立一个Azure DevOps项目来更新我们的网站。
我建立了一个测试网站,并让它正常工作,这样每当我推Git时,它就会自动发布

我遇到的问题是,测试网站有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应用程序部署

仅释放带有管道的已更改文件

在使用
copy
任务或
PublishBuildArtifacts
时,没有这种现成的方法只拾取修改过的文件

作为解决方法,我们可以添加powershell任务来删除时间戳为<(现在为-x min)的所有文件(递归),通过这种方式,工件目录只包含更改的文件

请在此处查看详细信息:

我尝试使用我的lame PowerShell技术开发此脚本,但没有成功


希望这有帮助。

我能够根据此线程中另一个答案的建议创建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)'

任务的脚本部分应该在一行中,但为了便于阅读,我对其进行了扩展。

我们确实遇到了同样的问题,不得不检查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
请注意,上面的代码工作得非常好,因为每行开头都有制表符/空格,所以只能复制粘贴,我们需要在实际运行构建之前验证代码


快乐的编码

预览功能“Pipeline artifacts”有一个过滤机制(.artifactignore)-有用吗?@AmittaiShapira它看起来必须设置为忽略特定文件,即使它们更改,我希望它忽略所有文件,除非它们更改。如果这有道理的话。比如,如果file1.html发生了变化,那么就把它推过去,但是file2.html保持不变,所以不用担心。是的,这是有道理的。。。从源代码看,这项任务似乎在内部使用Robocopy。我在CopyFiles任务(也使用Robocopy)中的经验是,它会忽略未更改的文件。。。该任务的源代码在GitHub中:@LeoLiu MSFT我还没有弄明白如何使用powershell实现这一点。我和孩子们一起玩CopyFiles@2任务,但我遇到了一些问题,我想我对每件事的工作原理缺乏一些了解。我的经验是,复制文件任务只会替换目标目录中更改的文件。。。但是,正如您所提到的,您始终可以在powershell任务中使用Robocopy(或类似产品)