Bulk Assign Permission Scheme

Patrice Champet
Contributor
July 1, 2021

Hello,

I am trying to create a simple script to bulk assign permission scheme on a list of project using scriptrunner.

My script looks like that: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.permission.PermissionSchemeService
import com.atlassian.jira.permission.PermissionScheme
import org.apache.log4j.Logger

def log = Logger.getLogger("ch.vaudoise.project.bulkedit.permissionScheme")

// Get the Project Manager
def projectManager = ComponentAccessor.getProjectManager()
def pss = ComponentAccessor.getComponent(PermissionSchemeService)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

//######################################################################################
// VARIABLES
def permissionScheemeID = 11201
// This will be the list of all the projects, testing script for 1 project now
def projs_key = ['RCVI','AIARUN','CBCV','DOMVIE','SDPV','EMDPAP','AIAMAIN','PYTHONSDP','PPRE','PU','AIADC','AIAINVAL','AIARENTVIA','RFISC','AIARYTDZ','VAVALOR','RIA','AIATREND']
//######################################################################################

// Iterate over each Project Object
def project = projectManager.getProjectObjects()

project.each {

try {
if (projs_key.contains(it.key))
{
PermissionScheme permscheme = pss.getSchemeAssignedToProject(currentUser,it.id).get()
def permschemeName = permscheme.getName()
log.info "project = ${it.key} , previous Scheme = ${permschemeName}"
pss.assignPermissionSchemeToProject(currentUser, permissionScheemeID, it.id)

}
}
catch(e)
{
log.error "Ran into a problem for ${it.key} n\" + e.message"
}
}

 

But it trigger a NullPointerException when executing.

Do you already faced any issue with assignPermissionSchemeToProject or do you have any idea what is wrong with this script ?

 

 

0 answers

Suggest an answer

Log in or Sign up to answer