Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Azure DevOps] Leave the original Build Number when no GitVersion variable in Build Number #1770

Merged
merged 3 commits into from
May 9, 2020

Conversation

kirkone
Copy link
Contributor

@kirkone kirkone commented Aug 9, 2019

The Build number should not replaced when there is no GitVersion variable in it.

This is discussed in #1457

Copy link

@tests-checker tests-checker bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add tests to make sure this change works as expected?

@kirkone
Copy link
Contributor Author

kirkone commented Aug 9, 2019

Could you please add tests to make sure this change works as expected?

I can not find a place where to place these tests. Any help?

@kirkone kirkone changed the title Leave Build Number with no GitVersion variable [Azure DevOps] Leave the original Build Number when no GitVersion variable in Build Number Aug 15, 2019
@kirkone
Copy link
Contributor Author

kirkone commented Sep 19, 2019

I it possible to get a review on this PR?

@arturcic
Copy link
Member

Sorry for not coming back. To be honest the idea to disable BuildNumber override looks good to know, but I'd prefer to have a more consistent approach, we need to add this ability to all supported CICD not only Azure pipeline, what do you think?

@kirkone
Copy link
Contributor Author

kirkone commented Sep 19, 2019

As far as I can see the other pipelines do not behave like this already.
This seems to be only in the code for Azure DevOps.
In AzDO the BUILD_BUILDNUMBER environment variable is also used as the name of the build.
When I use a build name "My Awesome Build" in the current version of GitVersion this will be replaced by "PackageName.1.0.5...".

I can have a look into the other pipelines again and make this sure.

@kirkone
Copy link
Contributor Author

kirkone commented Sep 19, 2019

I do not know the other pipelines enough to understand what setting the Build number will have for konequences.
Maybe the Solution mentioned here is more consistent:
#1457 (comment)

I do not know how to implement such a switch but this would allow to disable the the setting of the BuildNumber completly.

The change I made here is only the leave the BuildNumber untouched when there is no GitVersion variable in it. In my opinion this has no side effects to the other pipelines.

@kirkone
Copy link
Contributor Author

kirkone commented Oct 10, 2019

@arturcic I checked again and I think the behavior of replacing the whole string when no variable is in it is a thing only in the implementation of the Azure DevOps part.

If you still want the current behavior you can use something like that in your build name: "$(GitVersion.SemVer)".

What do you think?

@arturcic
Copy link
Member

arturcic commented Oct 10, 2019

As far as I can see, these are the CI providers that also override the build number:

AppVeyor - runs a PUT http request to override the build number
ContinuaCi - sets the setBuildVersion using their mechanism of messaging
Teamcity - sets the buildNumber using their mechanism of messaging
VsoAgent (aka AzurePipelines) - set the build.updatebuildnumber using their mechanism of messaging

So as you can see there are at least 4 CIs that by default override the build number. I do agree that VsoAgent does that in it's own way, it's trying to resolve GITVERSION variables in the string, and we should fix that to be consistent with the others.

And I do agree that we need to be able to disable the build number overriding in CIs but that should be done on the BuildServerBase level

@kirkone
Copy link
Contributor Author

kirkone commented Oct 10, 2019

OK, you are right, but can you give me a hint how to implement such a switch?

I also think that the difference ist how the build environment will handle the change of the buildnumber value. What I want to say is that only Azure Pipelines will use the build number also as the name for the build. I asked for splitting this up on their side but this is not possible as far as I know.
The other environments will not behave like this as far as I know.

@asbjornu
Copy link
Member

@kirkone, can you please submit a proposal for how you would like this implemented in a least common multiple of what all build servers support? Just a sketch so we have something concrete to discuss, because now it's all a bit too abstract for me to even comment on.

@stale
Copy link

stale bot commented Jan 16, 2020

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. Thank you for your contributions.

@stale stale bot added the stale label Jan 16, 2020
@arturcic
Copy link
Member

Bump

@stale stale bot removed the stale label Jan 16, 2020
@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

Hi @asbjornu ,

sorry for the late response.

I think the solution with the least impact on other Pipelines would be to add a new switch for the tool.
Something like --skipbuildnumber. If this is set the code block with the replacement will be skipped.

Aside from that I am very sure that replacing the whole string when there is no GitVersion reference in it is not the way most people would expect. If you want to use the replacement put a variable in the build name.

@arturcic
Copy link
Member

arturcic commented Feb 18, 2020

@kirkone seems to be a good idea. I would go with the --updateBuildNumber instead, meaning better to explicitly specify you need to update the build number. Or we can better have 2 configurations in the config file

updateBuildNumber - true|false
updateBuildNumberFormat - the build string format

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

@arturcic but this would be an breaking change then? So the tool would behave in a different way as before when it is called without the parameter?
Or do you mean the default value when not set is true?

@arturcic
Copy link
Member

Yes it looks like a breaking change. What I mean is if you want to enable a feature, better to specify you need to enable it, instead of not specifying. We can include in the release notes it's breaking change

@arturcic
Copy link
Member

@asbjornu Thoughts?

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

Is there also a way to include this setting in the .yaml file?

@arturcic
Copy link
Member

Is there also a way to include this setting in the .yaml file?

That will be the second option. Use config instead of cmdline switch. And I would prefer to have it as 2 configs, one to enable updating, and the other the format

@arturcic
Copy link
Member

Still this will be a breaking change

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

The format might not be necessary because if you want the replacement to happen then you easily can add variables to your Build name. That is the same way it works now.
I only want to change what happens if there is no variable set in the BuildName.

@arturcic
Copy link
Member

Ok, was thinking for all the Build Server we support. Are you in a position to work on a PR in that direction?

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

besides the changes I made so far I do not have any idea where to add new config values.
I will have a look into it again and update this PR.

@arturcic
Copy link
Member

You can start looking here https://github.com/GitTools/GitVersion/blob/master/src/GitVersionCore/Configuration/Config.cs

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

Startet a new approach ...

@kirkone
Copy link
Contributor Author

kirkone commented Feb 18, 2020

I added the configuration value but can not find an example how to access the configuration.

Should I get it from the DI?

@arturcic
Copy link
Member

arturcic commented Feb 18, 2020

I added the configuration value but can not find an example how to access the configuration.

Should I get it from the DI?

Check this https://github.com/GitTools/GitVersion/blob/master/src/GitVersionCore.Tests/ConfigProviderTests.cs

kirkone and others added 2 commits May 9, 2020 19:41
- Add an bool value to allow tuning on BuildNumber Replacement
  when no Variable found in the value of BuildNumber
@arturcic
Copy link
Member

arturcic commented May 9, 2020

@kirkone I have rebased on top of master and fixed/ added some tests. Thank you for the initial work and the thought process

@arturcic arturcic merged commit d0a1bea into GitTools:master May 9, 2020
@arturcic arturcic added this to the 5.3.x milestone May 9, 2020
@kirkone
Copy link
Contributor Author

kirkone commented May 10, 2020

Thank you @arturcic for finishing this!

I am very happy to see this. Sorry for not getting this ready, but I was not able to get those last changes running on my system.

Again, thanks! I will now prepare all my Pipelines to use this new feature.

@kirkone kirkone deleted the patch-1 branch May 10, 2020 12:19
@arturcic arturcic modified the milestones: 5.3.x, 5.3.3 May 12, 2020
@github-actions
Copy link

🎉 This issue has been resolved in version 5.3.3 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@kirkone
Copy link
Contributor Author

kirkone commented Aug 7, 2020

hello @arturcic

sorry for coming back to this but I missed a little detail in your changes.
setting update-build-number: false will disable all the output to the build Server. So there are all variables will not be set.

I do not think this is working like it should.

This here:

if (writer == null || !updateBuildNumber)

should look like:

if (writer == null)
{
    return;
}

if (updateBuildNumber)
{
    writer($"Executing GenerateSetVersionMessage for '{GetType().Name}'.");
    writer(GenerateSetVersionMessage(variables));
}
writer($"Executing GenerateBuildLogOutput for '{GetType().Name}'.");
foreach (var buildParameter in GenerateBuildLogOutput(variables))

Should I provide a new PR?

@arturcic
Copy link
Member

arturcic commented Aug 8, 2020

Yes please

@kirkone
Copy link
Contributor Author

kirkone commented Nov 17, 2020

Sorry for beeing so late here. I had some trouble in real live.

I created a new PR: #2457

@arturcic can you please have a look?

@arturcic
Copy link
Member

Glad you came back, hope you're better now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants