【问题标题】:Getting the last updated/commited file in git repository of VSTS在 VSTS 的 git 存储库中获取最后更新/提交的文件
【发布时间】:2017-07-16 23:27:07
【问题描述】:

我正在尝试调整 Azure 数据工厂管道的部署。换句话说,我计划仅将最近修改的管道或最近添加的管道部署到 Azure 门户中的 ADF。目前,我在我的 CD 管道中使用 powershell 任务来部署所有管道。如何使用时间戳获取最近修改的管道?任何建议都会有所帮助。 :)

【问题讨论】:

  • 你的意思是你想要 CI 和 CD 为你的 git repo 的最新提交更改的文件?但是构建和部署将适用于您最新提交的所有文件。
  • @Marina-MSFT HI Marina。构建所有文件,但仅根据时间戳推送/发布修改后的文件......这可能吗?
  • 是的,可以为所有文件构建并为更改的文件部署。我在回答中给出了方法。

标签: azure azure-devops azure-pipelines azure-data-factory azure-pipelines-release-pipeline


【解决方案1】:

如果您想构建所有文件但只推送/发布修改后的文件以进行部署,这是可能的。

您可以使用PowerShell任务获取$(Build.SourcesDirectory)中的最后一次提交id(sha-1值),然后使用git show <commit id>查找提交中更改了哪些文件,然后将这些文件复制到$(build.artifactstagingdirectory) .最后将这些文件发布到服务器。

【讨论】:

    【解决方案2】:

    您可以使用 REST API 获取更改的文件。

    简单的 powershell 脚本:

    Param(
     [string]$collection,
     [string]$project,
     [string]$repository,
     [string]$commit,
      [string]$token
    )
    $u="$($collection)$($project)/_apis/git/repositories/$repository/commits/$commit/changes"
    Write-Output $u
    $changedFiles=New-Object System.Collections.ArrayList
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$token)))
    $result=Invoke-RestMethod -Method Get -Uri $u -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -ContentType "application/json"
    
    Foreach($c in $result.changes)
    {
        If($c.item.isFolder -ne 'true')
        {
            Write-Output $c.item.path
            $changedFiles.Add(($c.item.path))
        }
    }
    

    参数(检查构建/发布定义中的允许脚本访问 OAuth 令牌选项):

    -collection $(System.TeamFoundationCollectionUri) -project $(System.TeamProject) -repository $(Build.Repository.Name) -commit $(Build.SourceVersion) -token $(System.AccessToken)
    

    【讨论】:

      猜你喜欢
      • 2012-10-17
      • 2015-09-20
      • 2011-06-05
      • 2017-02-20
      • 2022-10-17
      • 2020-10-10
      • 1970-01-01
      • 1970-01-01
      • 2021-07-20
      相关资源
      最近更新 更多