admin管理员组文章数量:1122846
In an Azure Pipeline I want to run git diff-tree
on the commits in the push that triggered the pipeline. In a Powershell task and using the Azure DevOps Services REST API I am able to get all the commit IDs for the current push.
Then, in that task I run & git diff-tree --no-commit-id --name-only $commitId -r
, but I get no output from this command.
I have tried to call it in various ways:
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
$files += @(& git diff-tree --no-commit-id --name-only $commitId -r)
Write-Host "Last exit code: $LASTEXITCODE"
}
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
& git diff-tree --no-commit-id --name-only $commitId -r > "$commitId.txt"
Write-Host "Last exit code: $LASTEXITCODE"
$files += @(Get-Content "$commitId.txt")
}
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
$files += @(Invoke-Expression "git diff-tree --no-commit-id --name-only $commitId -r")
Write-Host "Last exit code: $LASTEXITCODE"
}
All of these work locally, but when run in the Azure Pipeline it seems like nothing happens. $LASTEXITCODE
is always 0. Why does this not work?
In an Azure Pipeline I want to run git diff-tree
on the commits in the push that triggered the pipeline. In a Powershell task and using the Azure DevOps Services REST API I am able to get all the commit IDs for the current push.
Then, in that task I run & git diff-tree --no-commit-id --name-only $commitId -r
, but I get no output from this command.
I have tried to call it in various ways:
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
$files += @(& git diff-tree --no-commit-id --name-only $commitId -r)
Write-Host "Last exit code: $LASTEXITCODE"
}
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
& git diff-tree --no-commit-id --name-only $commitId -r > "$commitId.txt"
Write-Host "Last exit code: $LASTEXITCODE"
$files += @(Get-Content "$commitId.txt")
}
$files = @()
foreach ($commitId in $commitIds)
{
Write-Host "Commit id: $commitId"
$files += @(Invoke-Expression "git diff-tree --no-commit-id --name-only $commitId -r")
Write-Host "Last exit code: $LASTEXITCODE"
}
All of these work locally, but when run in the Azure Pipeline it seems like nothing happens. $LASTEXITCODE
is always 0. Why does this not work?
- 1 Probably the repository is a shallow clone that does not contain more than the head commit. Se this question for how unshallow. – hlovdal Commented Nov 22, 2024 at 9:59
- Yep, that was it. If you add that as an answer I'll mark it. – Nesh Commented Nov 22, 2024 at 10:19
1 Answer
Reset to default 1git diff-tree command requires at least depth 2 to get the changed files.
The cause of the issue is related to the fetch depth of the Pipeline repo.
By default, the Shallow fetch of the pipeline repo is 1 by default. Refer to this doc: Shallow fetch
New pipelines created after the September 2022 Azure DevOps sprint 209 update have Shallow fetch enabled by default and configured with a depth of 1. Previously the default was not to shallow fetch.
You can try to set the fetchDepth to 0 or >2 in YAML Pipeline.
For example:
YAML Pipeline:
steps:
- checkout: self
fetchDepth: 0
Classic Pipeline:
本文标签: Calling git command in Azure Pipeline Powershell writes no outputStack Overflow
版权声明:本文标题:Calling git command in Azure Pipeline Powershell writes no output - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736304757a1932343.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论