Unix Epoch notification parameter?


#1

Hi. Does anyone know if it’s possible to get a Unix Epoch value via notification parameters to be used in a Slack Notification attachment?

See Slack docs (https://api.slack.com/docs/message-formatting#formatting_dates) for a sample of formatting dates within the Slack notifications. The epoch value is required because this gets adjusted to the client date in Slack, instead of the Buddy execution datetime string.

For example:

// Currently supported
${execution.start_date} // returns a UTC date time string 

// Not currently supported?
${execution.epoch} // returns number value such as 1392734382

Slack Notification attachment sample:

[
	{
		"fallback": "$BUDDY_PIPELINE_NAME execution #$BUDDY_EXECUTION_ID",
		"color": "danger",
		"text": "<!date^1392734382^ at {time_secs}| >"
	}
]

If supported, the 1392734382 value above would be configured something like:

"text": "<!date^${execution.epoch}^ at {time_secs}| >"

Thanks in advance.


#2

oooh, so close…

"text": "<!date^${DateUtils.fromString(${execution.start_date}).getMillis()}^ at {time_secs}| >"

The following gets rendered to Slack:

<!date^1540692049976^ at {time_secs}| >

but the value is milliseconds and Slack requires seconds. So far I haven’t figured out a way to divide the value by 1000. If three digits were chopped off the value then Slack would accept:

 <!date^1540692049^ at {time_secs}| >

Support for simple math operations in the template parser would get this working, for example:

"text": "<!date^${DateUtils.fromString(${execution.start_date}).getMillis() / 1000}^ at {time_secs}| >"

#3

okay, figured it out finally by using the #set template directive which creates a custom param.

"text": "<!date^#set($epoch = $DateUtils.fromString(${execution.start_date}).getMillis() / 1000)${epoch}^ at {time_secs}| >"

Slack interprets the value correctly and renders the following time specific to the client app settings:

at 9:24:32 PM

Hope this helps.