[英]Azure DevOps YAML pipeline - git diff not working correctly
我正在我的 Azure DevOps YAML 管道中執行 git 命令,以通過 PowerShell 腳本獲取兩次提交之間的更改,例如git diff commit1 commit2 --name-only
- 請參閱下面的完整代碼:
Write-Information "git diff --name-only $git_event_before $git_event_after --diff-filter=ACM ""*.txt"""
$txt_files = @($(git diff --name-only $git_event_before $git_event_after --diff-filter=ACM "*.txt"))
$txt_files = $txt_files | ForEach-Object { Join-Path $root_path $_ | Get-Item }
if ($txt_files.Count -eq 0) {
Write-Error "Something went wrong, could not find any changed .txt files using the above 'git diff'"
}
這會引發一個錯誤,聲稱未找到任何文件。 但是,如果我在本地執行完全相同的git diff
命令,我也同步了存儲庫,它會按預期返回更改的文件。
我是否需要手動更新已由管道的結帳步驟下載的存儲庫?
你能嘗試以這種方式運行“git diff”嗎
$gitDiffCmd = 'diff "origin/{0}" "origin/{0}@{{1}}" --name-only' -f $buildSourceBranch
$gitCommitFiles = Invoke-Git $gitDiffCmd
function Invoke-Git {
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory)]
[string] $Command
)
try {
$old_env = $env:GIT_REDIRECT_STDERR
$env:GIT_REDIRECT_STDERR = '2>&1'
$response = Invoke-Expression "git $Command "
return $response
} catch {
Write-Host $_.ScriptStackTrace
} finally {
$env:GIT_REDIRECT_STDERR = $old_env
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.