-
Notifications
You must be signed in to change notification settings - Fork 658
Not planned
Not planned
Copy link
Description
Prerequisites
- I have written a descriptive issue titleI have searched issues to ensure it has not already been reportedTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
GitVersion package
AzureDevops task
GitVersion version
6.0.5
Operating system
Linux
What are you seeing?
I recently updated to the new GitTools tasks from UseGitVersion@5
along with new config and have had no issues building code for approximately a week. When I opened a pull request today, the automatic build triggered by our PR requirement failed stating that GitVersion is undefined. Looking at the logs, I can see that the checkout process is working as expected with all our most recent commits to the repository and we automatically tag every commit into master/main branches so history shouldn't be an issue. Any suggestions/workarounds would be appreciated.
What is expected?
Pull request builds should behave the same way when using GitTools in Azure DevOps.
Steps to Reproduce
# azure-pipelines.yaml job template
parameters:
- name: DependsOn
type: object
default: []
jobs:
- job: AdoBuildNumber
dependsOn: ${{ parameters.DependsOn }}
pool:
name: 'ubuntu-latest'
steps:
- checkout: self
fetchDepth: 0
- task: gitversion/setup@3.1.1
displayName: Install GitVersion
inputs:
versionSpec: '6.0.x'
- task: gitversion/execute@3.1.1
displayName: Determine Version
name: git_version # variable to use in subsequent steps
inputs:
overrideConfig: |
update-build-number=false
- pwsh: |
$build_number = "$(git_version.majorMinorPatch)-$(git_version.preReleaseLabel)-$(git_version.buildMetaData)"
echo "##vso[build.updatebuildnumber]$($build_number)"
displayName: 'Set Build Number using GitVersion'
# GitVersion.yaml
workflow: GitHubFlow/v1
strategies:
- Mainline
assembly-versioning-format: '{MajorMinorPatch}-{PreReleaseLabel}-{BuildMetaData}'
RepositoryFixture Test
No response
Output log or link to your CI build (if appropriate).
Starting: Determine Version
==============================================================================
Task : Execute GitVersion Task
Description : Easy Semantic Versioning (https://semver.org) for projects using Git
Version : 3.1.1
Author : GitTools Contributors
Help : See the [documentation](https://gitversion.net/docs/) for help
==============================================================================
Running on: 'Azure Pipelines'
Disable Telemetry
Command: git -C /agent/_work/15/s rev-parse --is-shallow-repository
Command: /opt/hostedtoolcache/GitVersion.Tool/6.0.5/dotnet-gitversion /agent/_work/15/s /output json /l console /overrideconfig update-build-number=false
##[error]GitVersion output is not valid JSON
dotnet-gitversion Output:
-------------------
undefined
-------------------
undefined
Finishing: Determine Version
DaveSkender, jainsid31, ThibaultLesuisse, cullub, stehubhex and 1 more
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
ChaosYoda commentedon Dec 24, 2024
I am running into the same issue, it seems to help to throw all the old agents away and try again. Seems the default Azure pipeline behavior is to do a detached head checkout, even if you set the fetchDepth: 0
DaveSkender commentedon Dec 30, 2024
This occurs on GitHub Actions too, so it's not likely an Azure DevOps specific issue.
I think in the end though the real problem here is that it takes a PhD to understand all the configuration options and all the different tool implementation options. I haven't solved all my problems, but am making progress by running the underlying
dotnet-gitversion
commands, which seem to produce better debugging information about your setup.Pre-defined GitHub Action tasks and output, for comparison
HHobeck commentedon Dec 30, 2024
Can you reproduce it locally and provide steps to reproduce? The undefined value is a strange result which I see the first time. Is this error related to the configuration (Mainline version strategy in combination with GitHubFlow/v1)? What happen if you just use the
GitHubFlow/v1
orTrunkBased/preview1
workflow template without customization? Is it related to your repository? What happen if you use a vanilla git repository?officeSpacePirate commentedon Dec 30, 2024
@HHobeck I tried going back to the GitVersion task using v6.0.x to see whether it would be a viable workaround. The build still fails, but it looks like GitVersion is failing to calculate on a PR branch. Here's the error from my build output:
Just to reiterate, the configuration I've mentioned so far works as expected locally and when building a branch directly in ADO; the failure only occurs for pull request builds. I'll try a few different configurations and get back to you if I have any luck.
officeSpacePirate commentedon Dec 30, 2024
@HHobeck Alright, I tried a few different configurations and it looks like
Mainline
is the problem. Hopefully this makes sense based on the error output in my previous comment. The configuration in my original post works if you simply remove thestrategies
property. I think this points to the issue being between v5.x and v6.x rather than the GitVersion task or ADO/GitHub.The problem is, I'm now unsure how to get my versioning structured the way I expect coming from v5. Is this a bug on GitVersion's end or do I need to change my configuration? Here's what we have on our master branch today using v5 in a .NET repository:
HHobeck commentedon Dec 30, 2024
Please try the TrunkBased/preview1 workflow:
If you have a merge from main to your feature or hotfix branch then this can be a problem as well. You should know currently
the feature to support multi mainline branches in the Mainline version strategy (#4057) is not implemented.
DaveSkender commentedon Dec 30, 2024
For my situation, I was able to determine that the issue is with the built-in task:
# works as expected dotnet-gitversion -output json -l console -config src/gitversion.yml
In other words, the built-in task is using
/
argument syntax that does seem to work. And just an FYI, with these commandsdotnet-gitversion
anddotnet gitversion
both work, butgitversion
alone does not.officeSpacePirate commentedon Dec 30, 2024
@HHobeck I was able to get a successful build after changing to
TrunkBased
, though it looks like the GitVersion property values change pretty significantly so I'll have to make sure I understand the expectations there.On a different note, it appears that the build only works when using the old GitVersion task. When I change back to the new way of doing things, I'm getting
undefined
as mentioned above. It's possible that @DaveSkender has already determined the root issue to that though.officeSpacePirate commentedon Dec 30, 2024
In case anyone else is running into this issue, here's my current workaround:
The use of
CommitsSinceVersionSource
is to avoid+
's because they are invalid characters in versions for container registries. It looks like usingTrunkBased
doesn't include one now, butGitHubFlow
does so I'm simply being explicit. Another note is that theBuildMetaData
property is null when usingTrunkBased
, so I decided on the one that seemed to make the most sense.HHobeck commentedon Dec 30, 2024
Please see following Q/A:
officeSpacePirate commentedon Dec 30, 2024
@HHobeck That's actually what I tried first, but it is not unique between builds/commits. When automatically publishing packages, I essentially need the FullSemVer, but without a + in it. Since BuildMetaData is null when using TrunkBased, I opted for CommitsSinceVersionSource. Another option would be to use ShortSha if character length is not an issue.
HHobeck commentedon Dec 30, 2024
I don't understand what you are writing. If you use the Continues Deployment mode then the pre-release number will be incremented on every commit. I think you have a misunderstanding about how the modes are working. Even though in the TrunkBased/preview1 workflow you can customize it (the pre-release number will be always 1 on the main branch because of the Mainline version strategy algorithm).
ChaosYoda commentedon Dec 30, 2024
I think what he is trying to say is that Continuous Deployment mode will keep incrementing but with a
+<number>
at the end. This is not compatible with Nuget versioning, even though the number is accepted nuget drops off the+<number>
and it leaves you with the same version as the previous build, where v5 had the padded commit number which could be used. The problem is mainly that the +234 or whatever postfix is not compatible.officeSpacePirate commentedon Dec 30, 2024
Are you saying that the default
mode
isManualDeployment
? I was under the impression that it wasContinuousDelivery
, which is what I want.To be specific, the repo I'm updating is currently set to v5 and the following:
Which results in
FullSemVer
as{Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber or CommitsSinceVersionSource}
I updated to v6 and tried:
Which results in
FullSemVer
as{Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber}+{BuildMetaData or CommitsSinceVersionSource}
. In this case,PreReleaseNumber
is always1
no matter how many commits I have on a non-main branch. I also can't have the+
for building or publishing containers, so I added the override to use theAssemblySemVer
as my default. This configuration is also the one that works locally and when building a branch directly in ADO, but does not work when building pull requests.I then opened this GitHub issue and tried your suggestion:
Which results in
FullSemVer
as{Major}.{Minor}.{Patch}-{EscapedBranchName}.{PreReleaseNumber or CommitsSinceVersionSource}
. In this case,BuildMetaData
is alwaysnull
, but theFullSemVer
doesn't have a+
in it causing an issue either. As I mentioned above, I only kept the custom versioning because of the differences betweenGitHubFlow
/TrunkBased
and I wanted to be explicit. This also resolves the issue I'm having with PR builds so long as I useUseGitVersion@5
instead ofgitversion/execute@3.1.1
for now.2 remaining items
DaveSkender commentedon Jan 2, 2025
Here's ^^ a bit of a repro, but generally it's working with my use case, despite the persistent UNDEFINED runner console output.
officeSpacePirate commentedon Jan 2, 2025
@DaveSkender I'm seeing
undefined
on thesetup
step everytime either way; don't know whether the additional info is useful.@HHobeck From my end, exactly the same configuration will return different results in ADO depending on whether I use
UseGitVersion@5
with the version set tov6.0.x
orgitversion/execute@v3.1.1
. The latter works when building locally or building a branch directly, but does not work when auto-building pull request branches; the former always works.It might be worth mentioning that ADO (and I believe GitHub Actions as well) automatically create a new branch including the current target branch and the changes in the source branch in the pull request before running any subsequent build steps. I'm not confident on whether that branch is of the target with the source merged in or of the source with the target merged in, but I suspect that this has something to do with GitVersion being unable to determine versioning.
Considering that this works as expected in v5 as well as the deprecated
UseGitVersion@5
task, but not the newer task, I would expect this to be a bug on GitVerison's side at this point.officeSpacePirate commentedon Jan 3, 2025
@HHobeck I noticed that the
Mainline
strategy is included in the default config forTrunkBased
and decided to test through some additional scenarios. It looks like using the default config works in ADO with thegitversion/execute@v3.1.1
as expected, so I've gone ahead and removed the two properties I was providing. Based on the build output and the GitVersion docs however, I still have no idea why it worked or why my previous configuration failed with onlygitversion/execute@v3.1.1
and notUseGitVersion@5
. It's also worth noting thatgitversion/execute@v3.1.1
has a version constraint that does not allow for v6.1.1 (latest) to be used, but it works without issue if I useUseGitVersion@5
.Since I am completed unblocked, feel free to close this ticket out. If you have time to explain what was causing the issue, I would really appreciate any extra insights for future development. Thanks for all the time you've already given me.
d-barker commentedon Jan 13, 2025
Thanks for the info! Changing the workflow did fix my issue.
I had a similar issue in my DevOps pipeline where this stopped working today (2025-01-13 - was working yesterday). In my case the issue was building a pipeline on a bugfix branch.
Here is the devops git version config that I am using:
I can confirm that changing the workflow fixed my issue, changing the GitVersion.yml as follows:
to
This thread has saved me some time, so thanks to all!
Duranom commentedon Jan 29, 2025
Noticed the undefined as well in azure devops pipelines when using
workflow: TrunkBased/preview1
Problem might be that "merge from master" feature is used to get latest from the trunk into the current feature, and potentially not using feature branch but accidental a different mistyped variant. (Thus hitting the 'unknown' configuration)
However when it happens a rebase seems not succeed either so a full new branch is normally created with cherry picks from the one that experiences it.
It might be most likely due to the following:
Hopefully #4057 will get some attention for such weird cases, as trunkbased is really something simpler to use in most cases but the undefined is really a heavy blow when encountered
ThibaultLesuisse commentedon Jan 31, 2025
I had the same error (output was undefined) recently and by adding this step before the gitversion I got it fixed for our organization. I have no clue as to why or how so take this with a grain of salt:
pfaustinom1 commentedon Feb 12, 2025
I'm facing the same issue.
I've tried to see the differences between @0 and @3 version, as I was using @0 previously and everything was working correctly:
Logs from @0:
Logs from @3:
DSpirit commentedon Mar 3, 2025
I've also encountered the same issue using the gitversion@3 tasks, however none of above solutions worked for me.
Since some of the builds succeeded, I've assumed it has to be something with the installation itself.
After digging into the logs, it seemed that gitversion/setup didn't run as expected and installed the tool into another directory.
Running
ls $env:GITVERSION_PATH
resulted in:which I've found is an Azure DevOps specification for installing tools (check following doc).
In order to handle this, I've configured my pipeline as follows:
The second step checks the installation path and adjusts it accordingly. As this is rather an ugly workaround, I'd assume it can be easily fixed.
Whenever a build previously failed, I've now get a log like:
Setting 'GITVERSION_PATH' to '/agent/_work/_tool/GitVersion.Tool/6.0.5/x64'
Switch to TrunkBased/preview1
Release/1.0.1 (#89)
github-actions commentedon Jun 2, 2025
This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs.
github-actions commentedon Jul 2, 2025
This issue was closed because it has been stalled for 30 days with no activity. Thank you for your contributions