(solved) Set Project Lead with Groovy/Script Runner

Tom March 11, 2020

Hello everybody,

i try to set the project lead a project with Groovy/Scriptrunner.
I have already seen and tested post Set Project Lead with Script Runner .


I have the problem that the username is set in the project, but when I check the result via GUI the message

"Looks like we can't find the selected project lead.

They may have been deleted from your instance. Click 'Edit defaults' to select a new project lead."

is displayed and the user is not showed recognized as JIRA user.

On edit screen, the right JIRA user is displayed. If I close the screen with "update" the user is now correct.

 

Is there are final command to complet to set the project lead?

 

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

def originalproject = ComponentAccessor.getProjectManager().getProjectObjByKey("APP1")
def name = "AAA"
def description = "test"
def String leadkey = "jira_admin" // this is username in my JIRA instance
def url = ""

ComponentAccessor.getProjectManager().updateProject(originalproject,name,description,leadkey,url,AssigneeTypes.UNASSIGNED)

 

2 answers

0 votes
Pavel Tyumenev September 2, 2020

Hi Tom, 

Seems like you are trying to define username to the leadkey variable, but you should define User Key.

try adding the next two lines to your code:

import com.atlassian.jira.user.ApplicationUser

def String leadkey = ComponentAccessor.userManager.getUserByName("jira_admin").key

it should help 

Tom September 2, 2020

Thank you for your answer, but I have allready fix it with this solution:

I forgott this threat :( 

Is maybe not the smart solution, but is works.

 

// BenutzerListe aufbauen
Collection<String> BenutzerCollection = new ArrayList<>();
for(item in issue.getCustomFieldValue(destProjectAdmins) ) {
def tmp = (ApplicationUser)item
BenutzerCollection.add( tmp.getKey() );
}

// BenutzerListe als PAdmin setzen
projectRoleService.addActorsToProjectRole(BenutzerCollection,
projectRole,
ProjektPM,
ProjectRoleActor.USER_ROLE_ACTOR_TYPE,
errorCollection)

// test
if ( errorCollection.hasAnyErrors() ){
log.warn("Error")
}

  

0 votes
Daniel Wong
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.
March 11, 2020

Hi Tom,

I haven't had time to test this, but I can see you added "String" into the line:

def String leadkey = "jira_admin"

This seems different from the original code provided by Alexey.

Can you try taking String out so you're not defining the object to be a String value? 

Tom March 12, 2020

Hello, Daniel,
thank you for your answer.
I have tested it again - but it makes no difference.

Tom March 19, 2020

No other ideas?

Suggest an answer

Log in or Sign up to answer