question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with running GitVersion on Build Server through Cake

See original GitHub issue

When running GitVersion using:

gitversion /output buildserver

the idea is that GitVersion will assert the semantic version of your git repository, and it will then create a number of Environment Variables, which can then be later used within your build script.

You can see GitVersion creating these environment variables in the log file here:

https://ci.appveyor.com/project/GaryEwanPark/resharperreports/build/0.3.0-PullRequest.16+7 (Build 28)#L169

Now, before I started using Cake, I used psake, and when executing GitVersion (using the buildserver flag) from my psake script, I was immediately able to consume the environment variables, as you can see here:

https://github.com/chocolatey/ChocolateyGUI/blob/develop/BuildScripts/default.ps1#L440

i.e. GitVersion is called here:

https://github.com/chocolatey/ChocolateyGUI/blob/develop/BuildScripts/default.ps1#L439

and the environment variables are immediately consumed. Now, this “magic” was made possible on AppVeyor thanks to some work that was done by @FeodorFitsner which allowed the psake (PowerShell) calling script to immediately “see” the environment variables created by GitVersion. i.e.

PowerShell -> GitVersion = works!

However, in the case of running GitVersion through Cake, we have:

PowerShell -> Cake -> GitVersion != works

So my question is, what needs to happen to allow this process to also work?

Is it a change to GitVersion? Is it a change to Cake? Is it a change to AppVeyor?

Is it not even possible?

There is a workaround, which is to call GitVersion twice. Once with the /output buildserver flag, which normalizing the Git Repository, and sets build number, etc, and once without that flag, to simply return the version number, but that feels like a bit of a hack.

There is also an open issue on GitVersion to also return the JSON result, when running with the buildserver flag, https://github.com/GitTools/GitVersion/issues/675, but not sure if this is going to get implemented or not.

Just wanted to put this out there to see what the thoughts were.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeGinnivancommented, Jan 23, 2016

The good news is that the next release of GitVersion will cache the version it calculates, so the second call will be almost instant.

0reactions
gep13commented, Jul 28, 2016

This will be implemented here: https://github.com/cake-build/cake/issues/1128

Read more comments on GitHub >

github_iconTop Results From Across the Web

GitVersion task in Cake Build script is missing library on ...
So I figured out the issue. I had a .gitignore file which removes the x86 and x64 folders from the git commits. Well,...
Read more >
Azure DevOps
To use GitVersion's variables in the build name, just add them in the form $(GITVERSION_FullSemVer) into the Build definition's build number string. Then...
Read more >
How to use GitVersion to get sensible versioning
GitVersion tries to fetch information from other branches as well, so you need to make sure that your build server ensures a non-shallow...
Read more >
GitVersion task in Cake Build script is ... - appsloveworld.com
Coding example for the question GitVersion task in Cake Build script is missing library on Azure DevOps when run.
Read more >
API - Cake.Common.Tools.GitVersion Namespace
Contains functionality related to GitVersion. In order to use the commands for this alias, include the following in your build.cake file to download...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found