Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to send an email to a slack channel specified via smart variable or similar

Bill Glynn
Contributor
November 22, 2021

I currently have an automation that will send an email to Slack Channel #1 (TEST) if the issue's (custom field) TestFlag is set to ON and send an email to Slack Channel #2 (LIVE) if the issue's (custom field) TestFlag is set to OFF. This works fine and enables me to test my automation via my Slack TEST channel. However, it requires me to test the (custom field) TestFlag and create identical email messages that only differ by the "TO" field, which contains the appropriate Slack channel email address.

I'd like to be able to test (custom field) TestFlag and set a smart variable, or a field inside the issue with the email address of the appropriate Slack Channel, use a single email message, and send that email by specifying the "TO" field with the smart variable or the field inside the issue (whichever works, I don't need both).

Is there a way to do this in Jira Cloud?

1 answer

1 accepted

1 vote
Answer accepted
Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 22, 2021

Hi @Bill Glynn ,

To answer your immediate question, which seems to be "can I use a smart value in the To: field?", the answer is yes. You'll want to create an If/Else block to compare the values of your "TestFlag" field - and then as an action in the if/else, set a variable for the email addresses you want to use. Here's an example of the conditions and actions:

image.png

Hint: in the "Send email" action, you can start typing a pair of curly braces and Automation will suggest that the address you're putting in is a smart value:

image.png

 

 

Does your rule strictly need to send an email? Would it be possible to use the "Send Slack message" action instead, which uses webhooks? The formatting of messages coming in through webhooks is significantly cleaner than emails, as well as a little bit faster. An additional advantage is that by using webhooks, you can override the channel the message is going to instead of having to know its email address in advance.

The if/else block logic would still be the same if you used the "Send Slack message" rule instead.

Although theoretically you could have a custom field for the Slack channel name, and then just call that directly as your smart value in the rule.

image.png

If you've got a field called "Slack Channel" and have put in a value like #test or #live into the field, you can achieve the same results with one action and no if/else block.

Cheers,
Daniel

Bill Glynn
Contributor
November 22, 2021

Voila, thanks Daniel, worked like a champ!!

I used your first method of a smart variable with the email address in it for now. I may get into the Web Hook method some other time, but for now I am very happy, thanks again!

Like Daniel Eads likes this
Bill Glynn
Contributor
December 2, 2021

Hi @Daniel Eads 

I'm not sure if I was hallucinating or if I actually did get things to work once, but I can't get the variable method to work at all. I create the variable in Picture1, then try to send email using the variable (Picture2), but it doesn't work. I can successfully send email to that slack channel directly (Picture3), so I know the channel works. Going back to Picture1, I've tried this method of setting the variable as shown, I tried putting the address in single quotes, and in double quotes - nothing works.

Any thoughts on what I may be doing wrong?

 

Set Variable.jpgSend Email without Variable.jpgSend Email with Variable.jpg

Bill Glynn
Contributor
December 2, 2021

Hi @Daniel Eads

I think I figured out that there is a bug in how variables are handled. Trying to set the variable by using an If/Else block fails for both conditions, the error in the rule says it's trying to send to an empty address. However, setting the variable and then changing the variable within a simple If condition works for both the original setting and within the If condition when it changes the value. See diagram.

Any thoughts?

Thanks, Bill

 

Slack Variable.jpg

 

Daniel Eads
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2021

Ah, good catch! I believe you're right - I have some rules where the variable is instantiated before setting the variable again inside the block, so that appears to be a critical step I left out for you here. Great troubleshooting!

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events