Octopus Release Version Template - Reset Next Suffix

I am looking at my release versioning in Octopus and have the following as my version template

#{if Octopus.Release.Channel.Name == “Master”}
1.#{Octopus.Version.LastMinor}.#{Octopus.Version.NextPatch}
#{/if}
#{if Octopus.Release.Channel.Name == “Dev”}
1.#{Octopus.Version.LastMinor}.#{Octopus.Version.LastPatch}#{Octopus.Version.Channel.NextSuffix}
#{/if}

The problem I am having is i want my releases to follow this format

Master #1 - 1.0.1
Dev #1 - 1.0.1.1
Dev #2 - 1.0.1.2
Dev #3 - 1.0.1.3
Master #2 - 1.0.2
Dev #4 - 1.0.2.1

What I cant seem to find is a way of resetting the next suffix variable after a master release has been created.

Is this something that is possible with Octopus Deploy?

The version I am using is v3.12.4

Thanks,

Stuart

Hi Stuart,

Thanks for getting in touch! I’m sorry for the delay in getting back to you! It turns out, just yesterday, we created a GitHub issue to look into adding this functionality to Octopus.

Below is the GitHub issue for reference.

So while there is no direct way to do this in Octopus currently, we are looking into adding this functionality. :slight_smile:

Let me know if you have any questions or run into any issues.

Best regards,
Daniel

Hi Daniel,

Thanks for this.

I have one question for you on the change that has been made and that is does the version template support nested if statements.

For example:

#{if Octopus.Release.Channel.Name == “Develop”}

#if(Octopus.Version.Channel[Master].LastMinor == Octopus.Version.Channel[Develop].LastMinor)
#{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}#{Octopus.Version.NextSuffix}
#{/if}

#if(Octopus.Version.Channel[Master].LastMinor != Octopus.Version.Channel[Develop].LastMinor)
#{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}-0
#{/if}

#{/if}

Hi,

I’m sorry for the delay in getting back to you. I have run this past the developer who made the changes here. Have you attempted to do this since you posted this? By the looks of it, this should work perfectly fine as it is. If you have tried this and run into any issues, you are more than welcome to let me know what went wrong, and we can try and resolve them.

Let me know. :slight_smile:

Best regards,
Daniel

Hi Daniel,

I have tried using this template but when I attempt to create a release the version number is not generated (see attachment).

Regards,

Stuart

Hi Stuart,

Thanks for getting back! That’s strange, it looks to be working fine on our end. Can you confirm that you have updated to at least Octopus version 3.13.0? As this is the version we released this functionality.

Looking forward to hearing from you. :slight_smile:

Best regards,
Daniel

Hi Daniel,

I can confirm the version in use is v3.13.0, the template works fine however when I take out the nested if statements so not sure if they cause the issue or not

Regards,

Stuart

Hi Stuart,

Thanks for getting back. One of the developers pointed out that your if statement is not using valid syntax. Sorry for any confusion, I didn’t notice initially.

#{if Octopus.Release.Channel.Name == "Develop"}
#if(Octopus.Version.Channel[Master].LastMinor == Octopus.Version.Channel[Develop].LastMinor) #{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}#{Octopus.Version.NextSuffix} #{/if}
#if(Octopus.Version.Channel[Master].LastMinor != Octopus.Version.Channel[Develop].LastMinor) #{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}-0 #{/if}
#{/if}

In your nested if, you are using #if() Octopus is only able to parse curly brackets for our variables and the if must be nested in the brackets like your initial statement. #{if }

So the working statement should look something like this:

#{if Octopus.Release.Channel.Name == "Develop"}
#{if Octopus.Version.Channel[Master].LastMinor == Octopus.Version.Channel[Develop].LastMinor} #{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}#{Octopus.Version.NextSuffix} #{/if}
#{if Octopus.Version.Channel[Master].LastMinor != Octopus.Version.Channel[Develop].LastMinor} #{Octopus.Version.Channel[Master].LastMajor}.#{Octopus.Version.Channel[Master].LastMinor}-0 #{/if}
#{/if}

Have a go with that and let me know if it works. :slight_smile:

Best regards,
Daniel