git - 如何在 Azure CI 管道上进行 git diff

标签 git azure continuous-integration azure-pipelines git-diff

我面临着让 git diff 在 Azure DevOps 管道环境中工作的挑战。这是管道脚本,用于将 git HEAD 与之前的提交进行比较,并仅复制已更改的文件。 git 命令在本地运行良好,但在 Azure 管道中会失败,因为 CI 运行中没有 HEAD^。寻求建议,这样的比较在 Azure 中是否可行,以及我如何实现这一目标。

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $targetfolder = "$(Build.StagingDirectory)" + "/"
      
      function CopyFiles{
          param( [string]$source )
      
          $target = $targetfolder + $source
      
          New-Item -Force $target
          copy-item $source $target -Force
      }
      
      $changes = git diff --name-only --relative --diff-filter AMR HEAD^ HEAD .
      
      if ($changes -is [string]){ CopyFiles $changes }
      else
      {
          if ($changes -is [array])
          {       
              foreach ($change in $changes){ CopyFiles $change }
          }
      }

错误消息如下所示: enter image description here

我认为在Azure管道设置中,当它检查重新定位时,它只提取最新的提交,而没有完整的提交历史记录。这就是为什么当 git 尝试获取以前的提交(例如 HEAD^)时,它找不到任何内容。

提前非常感谢您的帮助!

最佳答案

我刚刚找到了解决这个问题的方法。在这里为可能有类似问题的任何人发布答案。

默认情况下,构建代理在管道构建期间从存储库执行“浅层获取”。这仅获取最新的提交,没有任何其他提交历史记录。要获取更多提交或禁用浅层获取,请参阅此 doc来自微软。有一个选项可以指定提取深度或禁用浅层提取。

希望对你有帮助!

关于git - 如何在 Azure CI 管道上进行 git diff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74311232/

相关文章:

发布函数时未返回 Azure Functions V2 Http 错误代码内容

c# - 如果 ServiceBus 主题尚不存在,则创建它

maven - Intellij代码检查Maven插件

java - 使用 GIT 的 IDEA 新 gradle spring boot 项目。正确的创建顺序是什么?

git - 如何增加 git reflog 输出的条目数?

git SVN : fetching a recreated SVN branch without the wrong merge parent

python - 使用 Fabric 将当前的 git 分支部署到 heroku

python - Django 应用程序中的 Azure 云存储配置错误 : Could not load Azure bindings

kubernetes - "permanent"GKE kubectl 服务帐号认证

build-process - 生成失败的原因