Run automation if issue are added or removed from active sprint - Automation for Jira

Florian Pfaff October 30, 2020

We want to trigger a slack massage if an issue is either removed or added to the current sprint with automation for JIRA. How would I go about implementing this?

Especially I am unsure how to check if an issue was removed from the currently active sprint.

8 answers

1 vote
Pierre Liddle June 8, 2023

This is what I setup,

We only wanted to be notified for non-sub-tasks when new issues left or came in on the  current open sprints

Jira_Auto.png

Lucas Ferreira
Contributor
May 2, 2024

Hey @Pierre Liddle hope you are fine!

I'm trying to follow your automation, but I'm struggling to make it work properly.

I was able to 'half do' it. I'm getting notified when issues are being removed from the current sprint. However, I'm ALSO being notified when issues are being moved between future sprints, and I'm not being able to prevent that in the rules.

Would you be able to help me out here?

Pierre Liddle May 2, 2024

@Lucas Ferreira I'm not sure if this would help, but I'm showing the one extra condition in the flow that wasn't in the previous screenshot. I can't recall why, but I see we turned this off, and it might be related to the issue you're describing.

JiraAuto.png

Johnny Mon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 22, 2024

AFAIK, "{{opensprints()}}" returns null (or EMPTY).  There is no opensprints function in Smart Value.

We can use a smart value inside a JQL search, but I believe we can't call a JQL function inside a smart value tag as of today.  

Therefore, the logic presented will work the same if you replace "{{opensprints()}}" with EMPTY.  We can verify this by displaying the "{{opensprints()" in the A4J audit log.

 

0 votes
James Chan
Contributor
August 15, 2024

I have 3 scenarios:
A. an issue move from an active sprint to a future sprint
B. an issue move from a future sprint, into an active sprint
C. an issue move from a future sprint, to another future sprint

I used 3 branches, one for each scenario.

For scenario A - I just used JQL condition:

sprint in openSprints() AND issue = {{issue.key}}

Then add Jira comment or send an notification saying this issue moved from a future sprint to an active sprint.

 

For scenario B - I used JQL condition:

sprint not in openSprints() AND issue = {{issue.key}}

And then I used compare two {{smart values}} condition, NOTE: I needed to use "contains" rather than "equals". I guess Atlassian did some changes and "contains" no longer works.

Checks if: {{fieldChange.from}} contains {{opensprints()}}

Then add Jira comment or send an notification saying this issue moved from an active sprint to a future sprint  

 

For scenario C - I used a similar JQL condition and smart value comparison condition like in scenario B:

sprint not in openSprints() AND issue = {{issue.key}}
Checks if: {{fieldChange.from}} does not contain {{opensprints()}}

Then add Jira comment saying this issue moved from one future sprint to another future sprint. 

Johnny Mon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 25, 2024

Hi James,

Thanks for posting a solution.  I noticed a few issues below:

  1. The descriptions for scenarios A and B should be swapped.
  2. The scenario and solution for "an issue move from a future sprint, into an active sprint" will likely also true for "an issue is moved from backlog into an active sprint".  To avoid false positive notifications, we should account for scenarios involving moving from/to Backlogs.
  3. I believe the return value for {{opensprints()}} will always be EMPTY, because I am unaware of, as of today, there is a smart value function called "opensprints" and also unaware that smart value tag can execute a JQL function (e.g., opensprints).  We can check the content of smart values by displaying them to the audit log.
  4. {{fieldChange.from}} and {{fieldChange.to}} contains sprint IDs not in a sorted order, so the condition using text string 'Contains' function may not work 100% of the time.   For smart value lists, we need a contains() that is currently a feature request - JIRAAUTOSERVER-377  

 

0 votes
Dave Furlani
Contributor
June 4, 2024

While not simple to follow, this should help - https://confluence.atlassian.com/automationkb/send-notification-when-an-issue-is-added-or-removed-from-a-sprint-1333986992.html

If you're on Jira cloud, download and import the json file at the end of the article, and tweak as required

Varun Modi June 5, 2024

@Dave Furlani Thank you so much, that works!

0 votes
Johnny Mon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 21, 2023

This is a few years late, but I have a solution that works.  It is tested in Jira 8.20.10 and A4J 9.0.3.  I used web request instead of Slack for notification.

The hardest scenario is sending notification when an issue is moved between an Open and Future sprint.  IMHO, the following is a difficult: 

from: closed-sprint, active-sprint
to:  closed-sprint, future-sprint

Finding the delta between the 'from' and 'to' list using smart values requires using some Set theory and basic math.

The solutions that use the smart value "{{opensprints()}}" do not work for all scenarios.  As of version 9.0.3,  A4J does not how to call a JQL function inside a smart value tag.  So, what you get from {{opensprints()}} is actually a null (or EMPTY) value, because opensprints is undefined.

 

Solution

I put the solution in github: send-notification-add-remove-issue-sprint

  • README.MD - brief description of the rule
  • exported A4J rule that you can import into your system
  • screenshots of the rule
  • low resolution demo video

Premise

An issue's "sprint" field contains all previously participated closed sprints, plus possibly an open or future sprint.

When an issue's sprint is changed, the {{fieldChange.to}} and {{fieldChange.from}} records  contains a string of comma delimited sprint IDs.

During any sprint change in the A4J rule trigger there could be at most one sprint change, either one is added, removed, or changed (from open to future, or future to open).

Implementation

My solution uses Jira and A4J features.  It does not use JQL or ScriptRunner functions, which someone may have solved it using them.

My solution treats {{fieldChange.to}} and {{fieldChange.from}} sprint IDs as two Sets.  By using basic math and set theory (union and intersection), we can find the 'changed' sprint, then we call the REST API "agile/1.0/sprint/{{sprintID}}" using a web request action to get the 'changed' sprint's state to determine whether it's Open or Future.

summarized steps in the rule

  1. fromList = list of previous sprints

  2. toList = list of current sprints

  3. mergedList = fromList union toList

  4. removedSprintId = mergedList - toList

  5. addedSprintId = mergedList - fromList

  6. if a sprint was added then

    a. get the 'added sprint' record via REST API
    b. if the sprint is active (open) then send 'add' notification

  7. if a sprint was removed then

    a. get the 'removed sprint' record via REST API
    b. if the sprint is active (open) then send 'removed' notification

The solution uses a web request for notification (instead of slack).  You can easily replace it with another action such as email or slack.

Notes:

1) We need to update the following to make the rule work for you:

  • Replace the web request Jira REST API URL with your Jira's base URL.
  • Update the bearer token with of a Personalized Access Token from an account that can access project sprint information:  GET /agile/1.0/sprint
  • Replace the web request action that sends the notification with another action or your own webhook URL.  I used the free webhook.site for testing, but in production, you might want to send email to yourself for testing.

2) There are more details embedded in the rule's description.

3) For what is worth, the rule has simple examples on usage of the following that can be helpful on writing future rules:

0 votes
Nate Dame
Contributor
February 16, 2023

I can confirm the following...

This works for "added to current sprint":

Screenshot 2023-02-16 at 11.44.32 AM.png

And this works for "removed from open sprint":

Screenshot 2023-02-16 at 11.42.09 AM.png

Varun Modi February 16, 2024

This works, thank you so much for sharing!

Varun Modi February 19, 2024

@Nate Dame this works for me, but it also alerts me if I remove tickets from Future Sprints.

I want to be notified only if I remove ticket from current Active Sprint and not from Future Sprints, could you please help me with that?

Nate Dame
Contributor
February 19, 2024

I had the same problem @Varun Modi ! 

Honestly I gave up even though its not ideal.

If anyone has a solution I'm all ears!

Johnny Mon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 19, 2024

Hi @Nate Dame and @Varun Modi

I put my solution in GitHub: send-notification-add-remove-issue-sprint.  It will cover all add/remove issue from current or future sprints.  It sends notification via web request, which can be converted to Slack or email.

I also want to clarify that the Smart Value {{OpenSprints()}} will always return EMPTY (NULL), because we can't directly call the JQL function in a Smart Value expression.  

So, the expression 

{{fieldChange.from}} equals {{OpenSprints()}}
       is the same as
{{fieldChange.from}} equals NULL

Therefore, we will get notification when an issue is removed from active or future sprint.

 

0 votes
Rory Standley March 17, 2022

Hi @Florian Pfaff 

I believe you could probably try something like this for removal from a current sprint -

Screenshot 2022-03-17 at 10.56.51.png

For adding to a current sprint you could try this -

Screenshot 2022-03-17 at 10.57.58.png

Varun Modi February 19, 2024

@Rory Standley this works for me, but it also alerts me if I remove tickets from Future Sprints.

I want to be notified only if I remove ticket from current Active Sprint and not from Future Sprints, could you please help me with that?

0 votes
Alexander Eck [Tempo]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 2, 2020

Hi @Florian Pfaff ,

this is a tricky one I believe. I do not have an out of the box solution and the only way I see is to create a webhook that is fired by an Jira sprint updated event (you can create webhook urls in Slack). The webhook url could include the SprintID that has been updated. But even if you could use the SprinID to get all issues within the Sprint it would not help you as you will only get issues from the current sprint not the issues that have been removed. By searching across the internet I found some possible enablers like the Scriptrunner removedafttersprintstart function (and there might be similar on that you could use). 

Another idea might be to create a custom field (e.g. "original sprint"9 that keeps the Sprint of last assigned Sprint and then you could compare it towards the current Sprint.

Really everything is not straight forward and I would really be interested how others are solving this.

BR

0 votes
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 30, 2020

Hi @Florian Pfaff 

I don't think there is such an option...

These are the options for Sprints:

  1. When sprint completed
  2. When sprint created
  3. When sprint started

You can choose the "when issue edit" and check if the sprint value changed, but it will not check about active sprint or not active sprint

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events