Automatic date formatting

Hi guys

So we have a requirement to explicitly replace with an ISO format style date in a file, thus: 2030-07-07T09:05:00Z in string format. However when using a value like that as a variable value, on saving the change to the variable set Octopus is converting the value to a date like this 7/7/2030 9:05:00 AM.

Is there a way to escape this behaviour?

Cheers
Leslie

Hi Leslie,

Thanks for reaching out. Couple of questions about your current process:

  • Where are you getting the initial date value from and what’s its format?

  • What is the final format you are looking for?

  • How are you formatting it ? Using Powershell?

  • How are you saving the formatted value and where?

  • How are you replacing the value in the file using the variable?

Thanks!
Dalmiro

Hi Dalmiro

Sorry I think I’ve probably not explained the issue properly.

We’d like to do variable substitution in a file with #{StartTime} and the value we’d like is a date in ISO format as a string value, so for example: 2030-07-07T09:05:00Z

When we input the above string as the value of the variable with name StartTime in a variable set for a project in Octopus, on saving the variable set Octopus converts that string we’ve just set to a date in format 7/7/2030 9:05:00 AM instead. This is not the desired replacement value for the variable. Why is Octopus doing this and how can we stop it?

Cheers
Leslie

Hi Leslie,
We have certainly come upon this issue before and after a bit of investigation have found that a fix may be possible for this “bug”. The concern is that this fix may also impact other date variables that go into the collection and users may be relying on the current behaviour in their builds. As a result I have created GitHub Ticket #2610 so that it can be properly prioritised and addressed.

In the meantime you may be able to get around the problem by creating an output variable in a preceding script step that formats the date to what you are after. Since it wont be going in and out of the database it should sidestep the aforementioned bug. Its certainly not a great approach but should allow you to keep deploying while the bug remains outstanding.

Let me know if you have any further questions surrounding this, and keep an eye on the ticket to see how it progresses.
Thanks again for getting in touch regarding this behaviour,
Cheers,
Rob

Hi Rob

Thanks for the response, and thanks for raising the bug – I would imagine a somewhat unexpected result of storing the variable sets in the database.

Yes the output variable workaround is messy but tolerable I think and we’ll implement in the interim. I’ll keep an eye on the bug

Cheers
Leslie

Hi Leslie,
Thanks for your patience on this issue. We have since provided what we think is a good workaround for this serialisation problem by allowing the user to specify the format that they are after explicitly. One of the new format filters provided for variable from Octopus Deploy 3.5, allows for much richer conversion.

There are more details on both the ticket and docs, but the key change is the ability to use your variable like this:

#{MyDate | Format “dd-MMM-yyyy”}

which will result in it being formatted exactly how you want it (in this example as 07-Jul-2030).
Give this a go and let us know how it works for you.
Thanks again,
Rob