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

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,557,693
Community Members
 
Community Events
184
Community Groups

Listener sprintCreatedEvent only on certain project

I would my listener on the sprintCreatedEvent to only be triggered on a certain project. Currently the script below creates a version in a project when there is a sprint created in every project. 

 

{code}

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project

def sprintName = event.sprint.name


def version = ComponentAccessor.versionManager.createVersion(sprintName,
    null,
    null,
    sprintName,
    16400,
    null,false)

    return version.name

{code}

3 answers

1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 07, 2023

The following makes no sense:

def project = ComponentAccessor.projectManager.getProjectByCurrentKey("INTB2BSSD")

 if (project.key == 'INTB2BSSD') {

You hardcode a project lookup then check that the project is the one you just hardcoded?

No.

You need to use the information from your event to find your project.

The best way I was able to find to do that is to use the rapidViewId. As far as I know, usually, each rapidVIew (board) should be associated with a single project.

You might need to hardcode that mapping.

For example:

import com.atlassian.greenhopper.api.events.sprint.SprintStartedEvent

event = event as SprintStartedEvent
def boardProjectMap = [
123L: 'PKEY1',
345L: 'PKEY2',
567L: 'PKEY3',
]
def boardId = event.sprint?.rapidViewId
if(!boardId) return //nothing to do if we don't know the board
log.debug "found boardId from the event: $boardId"
def projectKey = boardProjectMap[boardId]
if(!projectKey) return //nothing to do if the board id didn't map to a projectKey
log.debug "found project key $projectKey from boardProjectMap"

def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)

the data in boardProjectMap will have to be updated to match your board and project keys

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 07, 2023

Hi @Atlassian TMG

Could you please share a screenshot of your listener configuration? I am requesting this to check if you have specified the projects you want the listener to work on in the configuration.

I am looking forward to your feedback.

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 07, 2023

Hi @Atlassian TMG

If you want the Sprint Listener to trigger for specific Projects only, try adding this filter:-

import com.adaptavist.hapi.jira.projects.Projects

def project = Projects.getByKey('MOCK')

if (project.key == 'MOCK') {
// Your code
}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

I am getting a error.

The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script660.groovy: 2: unable to resolve class com.adaptavist.hapi.jira.projects.Projects
 @ line 2, column 1.
   import com.adaptavist.hapi.jira.projects.Projects
   ^

1 error
.

@Ram Kumar Aravindakshan _Adaptavist_ we are currently still using script runner 6.57 and we cannot update intill we are migrated to jira cloud which will take a while.

@Ram Kumar Aravindakshan _Adaptavist_ , I changed the script to something similar but didn't work. It still keeps creating versions when a sprint is created in another project.

{code}

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project

def project = ComponentAccessor.projectManager.getProjectByCurrentKey("INTB2BSSD")

if (project.key == 'INTB2BSSD') {

 def sprintName = event.sprint.name  
 def version = ComponentAccessor.versionManager.createVersion(sprintName,
    null,
    null,
    sprintName,
    16400,
    null,false)


    return version.name
}
{code}

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 07, 2023

Hi @Atlassian TMG

I forgot to mention that you need to upgrade your ScriptRunner plugin to the latest rease, i.e. 8.0.0 so you can use the HAPI feature that is shown in the sample code I provided.

Thank you and Kind regards,

Ram

@Ram Kumar Aravindakshan _Adaptavist_ is there another cmd I can use? Because it's not possible to upgrade at the moment.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events