Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

The automation rule fired when an event executed leads to a wrong execution of the code

0

I am firing an event based on a transition called "Generate Features" executed as you can see below: enter image description here

Also, based on an automation rule, I am executing some code. Here is the automation rule that I have:

enter image description here

The problem is that I am getting a message saying that the issue does not have an component which is wrong since the issue that I am testing my code on has 2 components as you can see below: enter image description here enter image description here Here is the code to be executed as part of the automation rule:

package SuperFeature

import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager

    
def log = Logger.getLogger('atlassian-jira.log')
List < String > componentList = new ArrayList < String > ()
List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()
def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']

log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents())
if (issue.getComponents().size() == 0) {
    issue.update {
         String text = "Issue does not have any components\n"

        setCustomFieldValue('Execution Summary', text )
    }
} else if (issue.getFixVersions().size() == 0) {
    issue.update {
        String text = "Issue does not have any fix versions\n"
        setCustomFieldValue('Execution Summary', text)
    }
} else {
    int componentSize = issue.getComponents().size()
   
    int generatedIssuesCounter= 0
     for (ProjectComponent component: issue.getComponents()) {
                      String componentName = component.getName()
                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
                    def projectName = componentName.substring(0, componentName.indexOf("-"))
                
                        

                        if(projectNames.contains(projectName)){

                        
                        
                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                        //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList)
                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
                        def found = newList.any {
                            it.getName().equals(shortenedComponentName)
                        }
                        if (found) {
                            componentList.add(componentName+" ===> WILL BE GENERATED")
                            finalComponentList.add(component)
                            generatedIssuesCounter++
                        } else{
                            componentList.add(componentName+" ===> CANNOT BE GENERATED")

                        }
                        }
            
     }

     


    issue.update {
        String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n"
        
       text = text + componentList.join("\n")    ;
         // Partition a list into list of lists size 3
       

        setCustomFieldValue('Execution Summary', text)
    }
}
    

1 answer

0 votes
Tomáš Vlach
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.
Oct 12, 2023

Hello @Mouna Hammoudi

 

can you create new automation rule with Manual trigger from issue and then try to run in from the certain issue? Skipping the event triggering part? If the script is working correctly?

 

Thanks,

Tomas

@Tomáš Vlach yes, the implementation I had before was based on an issue update and it was working perfectly.

Tomáš Vlach
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.
Oct 12, 2023

In that case, in you current rule try to add component - FOR EACH: Create a branch - Branch rule / related issue - Current issue - Save and then in this component add run a script action.

 

Tom

@Tomáš Vlach 

 

I was wrong, I have used issue updated as an automation trigger for my rule and it's not working, I receive the message, the issue does not have any components even though the issue does have components. 

You can see it in these screenshots:

Capture3.PNGCapture2.PNGCapture1.PNGCapture.PNG

 

Here is the code which is supposed to be executed based on an issue update. I printed the issue and I have gotten the following: =====MOUNA CAMELIA ISSUE:::: SF-437 ISSUE COMPONENTS []

The issue components are empty which is obviosuly wrong. My issue does have components.

 

package SuperFeature

import com.atlassian.jira.issue.Issue

import org.apache.log4j.Logger

import com.atlassian.jira.project.version.Version

import com.atlassian.jira.bc.project.component.ProjectComponent

import com.atlassian.jira.bc.project.component.ProjectComponentManager

import com.atlassian.jira.security.JiraAuthenticationContext

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.label.LabelManager

   

def log = Logger.getLogger('atlassian-jira.log')

List < String > componentList = new ArrayList < String > ()

List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()

def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']

log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents())

if (issue.getComponents().size() == 0) {

    issue.update {

         String text = "Issue does not have any components\n"

        setCustomFieldValue('Execution Summary', text )

    }

} else if (issue.getFixVersions().size() == 0) {

    issue.update {

        String text = "Issue does not have any fix versions\n"

        setCustomFieldValue('Execution Summary', text)

    }

} else {

    int componentSize = issue.getComponents().size()

   

    int generatedIssuesCounter= 0

     for (ProjectComponent component: issue.getComponents()) {

                      String componentName = component.getName()

                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)

                    def projectName = componentName.substring(0, componentName.indexOf("-"))

               

                       

                        if(projectNames.contains(projectName)){

                       

                       

                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                        //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList)

                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());

                        def found = newList.any {

                            it.getName().equals(shortenedComponentName)

                        }

                        if (found) {

                            componentList.add(componentName+" ===> WILL BE GENERATED")

                            finalComponentList.add(component)

                            generatedIssuesCounter++

                        } else{

                            componentList.add(componentName+" ===> CANNOT BE GENERATED")

                        }

                        }

           

     }

     

    issue.update {

        String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n"

       

       text = text + componentList.join("\n")    ;

         // Partition a list into list of lists size 3

       

        setCustomFieldValue('Execution Summary', text)

    }

}

   

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events