Git short hash in version number

Hi all,

I’m having trouble acheiving something. What I want is to have my Git short hash included in the version number of my app (injected into appSettings in my web.config), like this 5.0.1.b6f62e5. So far I’ve failed to acheive this.

First attempt was to include the hash in the build number set in TeamCity using a powershell script, then I could just reference it easily from within Octopus and inject in into my web.config. This seemed to be working fine in teamcity but when I attempted my first deploy I got the error “error OCTONUGET: ‘5.0.1.b6f62e5’ is not a valid version string” - presumably because of the letters?

Second attempt was to pass the git hash from TeamCity to Octopus as prompt variable using command arguments. Works great for the first deployment in the lifecylcle but then it asks for the value on all subsequent deployments in the release. OK but not ideal, I want this done automatically really.

Third attempt was to try and set the value as an output variable but I soon figured out that again that would only work for a single release.

Any easier way to do this? Can I have a prompt variable that gets persisted through the whole lifecyle?

Thanks
Chris.

Hi Chris,

Thanks for getting in touch! You are correct about the first attempt issue, its not valid SemVer because of the letters, but you could get around it by changing the hash to be a tag ie: 5.0.1-b6f62e5 which will be an acceptable version number. I think out of all of your options this would be the easiest to work with.

We do have a UV suggestion for a persisted prompted variable, but it really hasn’t gotten much support.


If you want to swing by and add some votes or comments then it might have a better chance of being implemented.

Let me know what you think,
Vanessa

Thanks Vanessa, that’s a good alternative. I’ve voted that other suggestion up a little as I do think the environment scope variable would be quite handy.

Thanks again for you help.

Chris.