Using #{if} in a variable value

Hello,

I have a requirement to upload the contents of a NuGet package to an Azure blob container, where each blob should be prefixed with either rc\ or the the release number.

  • If the release number contains ‘rc’, all blobs should be pre-fixed with rc/
  • Otherwise, all blobs should be pre-fixed with the release number, e.g. 1.2.3/

The uploading of the blobs is fine, and I can define the prefix using a variable, but I’m finding issues when trying to use #{if} and #{else} to set the prefix variable. As you can see, I’m attempting to use Conditionals with Complex Syntax in conjunction with the Replace filter

#{if Octopus.Release.Number | Replace "[^a-z]" == "rc"}rc\{#else}#{Octopus.Release.Number}\#{/if}

However, using the above as a variable value results in that value being the blob prefix, meaning all my blobs are prefixed -

  1. #{if Octopus.Release.Number | Replace “[^a-z]” == “rc”}rc
  2. {#else}#{Octopus.Release.Number}
  3. #{/if}

I was wondering if the Extended Syntax wasn’t available to use in variable values, but the docs state -

It’s worth noting that this is now available everywhere whereas previously it was limited to certain scenarios.

Is there something wrong with my declaration, or is the documentation leading me astray?

Thanks,
David

Hi David,

Thanks for getting in touch!

This may just be a typo in your post, but I figured I’d take a swing at the low hanging fruit first.
The beginning of your if statement is missing the ‘c’ from Octopus: #{if Otopus.Release.Number

If this is correct in your implementation and it is still not working, let me know and I’ll create a test environment to figure this out.

Best regards,
Paul

Hi Paul,

Thanks for the reply.

The missing ‘c’ was a typo on here, but I have now found the issue - {#else} as opposed to #{else}.

I’m hoping that everything is working as expected now…

Thanks,
David

Hi David,

That’s great, let me know if you still have any problems with it.

Best regards,
Paul

I should also have said that I had to make an interim variable to do the replacement -

Az.StorageAccount.BlobPrefixFiltered: #{Octopus.Release.Number | Replace "[^a-z]"}

Az.StorageAccount.BlobPrefix: #{if Az.StorageAccount.BlobPrefixFiltered == "rc"}rc\#{else}#{Octopus.Release.Number}\#{/if}

Using the Replace filter within the #{if} Conditional does not work.

1 Like