<#assign message="<${executionData.href}|Execution #${executionData.id}> of job <${executionData.job.href}|${executionData.job.name}>">
<#if trigger == "start">
    <#assign state="Started">
<#elseif trigger == "failure">
    <#assign state="Failed">
<#else>
    <#assign state="Succeeded">
</#if>
{
   "attachments":[
      {
         "fallback":"${state}: ${message}",
         "pretext":"${message}",
         "color":"${color}",
         "fields":[
            {
               "title":"Job Name",
               "value":"<${executionData.job.href}|${executionData.job.name}>",
               "short":true
            },
            {
               "title":"Project",
               "value":"${executionData.project}",
               "short":true
            },
            {
               "title":"Status",
               "value":"${state}",
               "short":true
            },
            {
               "title":"Execution ID",
               "value":"<${executionData.href}|#${executionData.id}>",
               "short":true
            }
<#if trigger == "failure">
            ,{
               "title":"Faild Nodes",
               "value":"${executionData.failedNodeListString}",
               "short":false
            }
</#if>
]
      }
   ]
}


<#assign message="<${executionData.href}|Execution #${executionData.id}> of job <${executionData.job.href}|${executionData.job.name}>">
<#if trigger == "start">
    <#assign state="Started">
<#elseif trigger == "failure">
    <#assign state="Failed">
<#else>
    <#assign state="Succeeded">
</#if>
{
   "attachments":[
      {
         "fallback":"${state}: ${message}",
         "pretext":"${message}",
         "color":"${color}",
         "fields":[
            {
               "title":"Job Name",
               "value":"<${executionData.job.href}|${executionData.job.name}>",
               "short":true
            },
            {
               "title":"Project",
               "value":"${executionData.project}",
               "short":true
            },
            {
               "title":"Status",
               "value":"${state}",
               "short":true
            },
            {
               "title":"Execution ID",
               "value":"<${executionData.href}|#${executionData.id}>",
               "short":true
            }
<#if trigger == "failure">
            ,{
               "title":"Failed Nodes",
               "value":"${executionData.failedNodeListString!"- (Job itself failed)"}",
               "short":false
            }
</#if>
]
      }
   ]
}


Fix Exception when the job itself has failed.
Fix Exception when the job itself has failed.

A Rundeck job can fail before any nodes have failed.
This causes an exception:

	> Caused by: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:
	> ==> executionData.failedNodeListString  [in template "slack-incoming-message.ftl" at line 39, column 27]
	>
	> Tip: If the failing expression is known to be legally null/missing, either specify a default value with myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthessis:
	> (myOptionVar.foo)!myDefault, (myOptionVar.foo)??
	>
	> The failing instruction:
	> ==> ${executionData.failedNodeListString}  [in template "slack-incoming-message.ftl" at line 39, column 25]
	> 	at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:98)
	> ...

This prevents the notification from being sent, so print a default message
instead.
