Closed actionthomas closed 1 year ago
Thanks @actionthomas for trying out PR Metrics and for your detailed response.
Unfortunately, I don't have access to Azure DevOps Server, so I'm not able to try this out locally. It looks like Azure DevOps Server is using the commit SHA as the branch rather than the standard same branch name format.
Earlier in the run, you should be able to see where Azure DevOps checks out a branch with the contents it's running locally. In my case, I see this at the top the checkout command with a statement like: Starting: Checkout <repo>@refs/pull/2138197/merge to s...
Can you find the line, so that we can see what is the correct branch format should be?
Hi @muiriswoulfe and thanks having a look at this issue so quickly :)
I have the same line here at checkout : Démarrage : Extraire <repo>@refs/pull/37574/merge pour s
.
The error message from PR Metrics mentions PR number 42422 while the last statement you have mentions PR number 37574. Are they from different PRs? I'm trying to narrow down whether the difference is relevant.
Oh yes, the message is from a different PR, but they have always this form.
For PR 42422 it's Démarrage : Extraire <repo>@refs/pull/42422/merge pour s
.
It's a very strange error in that case, as I don't see why git would be confused about the branch that exists. Can you try this on another repo on the same server (and ideally on another server too if you have one), to see if this is localised? Others had been using PR Metrics on Azure DevOps Server before so I'm confused as to why this would be failing now.
I tried with a different repo, this one isusing classic builds. The result is the same. Unfortunately, I don't have another server to test with.
Thanks for performing the check.
I've read through your detailed output again, and the first thing I would like to check is whether the issue still occurs when comparing against your main
branch, e.g.:
variables:
- name: realBranchName
value: $[replace(variables['Build.SourceBranch'], 'refs/', '')]
- name: realTargetName
value: origin/main # Or whatever the name of the main branch is called for your repo.
# other stuff...
- task: CmdLine@2
inputs:
script: |
git diff --numstat --ignore-all-space $(realTargetName)...$(realBranchName)
git rev-parse --branch $(realTargetName)...$(realBranchName)
The reason I'm asking, by the way, is because most people run PR Metrics against the main
branch so I'm wondering if that is why it is failing in your case. That said, it should work against the develop
branch as well.
To fix this, I'm not seeing a great alternative other than to:
To validate that this would be an appropriate action to take, could you confirm that the output you provided above (and listed below) is roughly correct, so that we wouldn't be just calculating and displaying incorrect information?
6 1 Sources/azure-pipeline.yml
1 1 Sources/<redacted file 1>.cs
51 0 Sources/<redacted file 2>.sql
5 1 Sources/<redacted path>/PostDeploymentScript/Script.PostDeployment.sql
2 0 Sources/<redacted file 3>.sqlproj
By the way, I'm a little concerned that this plan may result in the suppression of genuine errors, so I'm open to other suggestions. Perhaps you have noticed something I missed given your interaction with the Azure DevOps Server.
I performed the steps you asked, running the script against our master branch. I had the same warnings, unfortunately. I can also confirm that the changes reported by the git command are correct.
Thanks for checking again. I'll put this on the backlog as an item to fix. I unfortunately can't guarantee when I'll get around to it as there are other items of higher priority. Feel free to contribute a solution if you need to get something in more quickly.
@actionthomas It unfortunately took me some time to try to reproduce this locally, but I finally managed to get around to it. However, with a local instance of Azure DevOps Server, I'm not seeing the issue.
My guess is that this isn't specific to Azure DevOps Server, and that it is due to something that is different in your environment. That makes it much more difficult to resolve as my previous proposal of checking whether the run is executing on Azure DevOps Server will no longer resolve the issue, except potentially in your case.
I'd like to implement the fix properly if we need to make some change here, but I'm at a loss as to what that would be. Is there anything else you can think of that may be causing the issues on your side?
Is it necessary to set fetchDepth = 0? my code repo size is very big, like 80g, so can I just pull a little commit ? like fetchDepth = 1 or fetchDepth = 200?
Summary
PR Metrics task fails with message
Could not access sufficient Git history. Set 'fetchDepth: 0' as a parameter to the 'checkout' task (YAML) or disable 'Shallow fetch' under the build process phase settings (classic).
even thoughfetchDepth
is set.Reproduction Steps
Here is an extract of the yaml present in the pipelines :
Troubleshooting Undertaken
I injected a script to execute the command provided in the troubleshooting document, and one mimicking what the extension does.
Script output
```txt warning: refname 'pull/42422/merge' is ambiguous. 6 1 Sources/azure-pipeline.yml 1 1 Sources/PR Metrics task output
```txt 2023-07-07T08:46:56.4357848Z ##[debug]Evaluating condition for step: 'PR Metrics' 2023-07-07T08:46:56.4359744Z ##[debug]Evaluating: SucceededNode() 2023-07-07T08:46:56.4361506Z ##[debug]Evaluating SucceededNode: 2023-07-07T08:46:56.4362936Z ##[debug]=> True 2023-07-07T08:46:56.4363455Z ##[debug]Result: True 2023-07-07T08:46:56.4363919Z ##[section]Démarrage : PR Metrics 2023-07-07T08:46:56.4556637Z ============================================================================== 2023-07-07T08:46:56.4556882Z Task : PR Metrics v1.5.4 2023-07-07T08:46:56.4557010Z Description : Augments pull request titles to let reviewers quickly determine PR size and test coverage. 2023-07-07T08:46:56.4557574Z Version : 1.5.4 2023-07-07T08:46:56.4557702Z Author : Microsoft Corporation 2023-07-07T08:46:56.4557854Z Help : https://aka.ms/PRMetrics/README 2023-07-07T08:46:56.4557991Z ============================================================================== 2023-07-07T08:46:56.5161684Z ##[debug]Using node path: E:\agent\1\externals\node10\bin\node.exe 2023-07-07T08:46:56.7994100Z ##[debug]agent.TempDirectory=E:\_w\1\_temp 2023-07-07T08:46:56.8028164Z ##[debug]loading inputs and endpoints 2023-07-07T08:46:56.8029042Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN 2023-07-07T08:46:56.8045793Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION 2023-07-07T08:46:56.8056461Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION 2023-07-07T08:46:56.8066220Z ##[debug]loading SECRET_AGENT_PROXYPASSWORD 2023-07-07T08:46:56.8069697Z ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN 2023-07-07T08:46:56.8083988Z ##[debug]loaded 5 2023-07-07T08:46:56.8092562Z ##[debug]Agent.ProxyUrl=Additional Information
My ADO agents are in version 2.218.1.
Thank you for your help.