My groovy script to change component leads does not work

Hi Guys,

Can someone tell me what I am doing wrong here. Thanks in advance!

import groovy.json.JsonSlurper;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("com.acme.CreateSubtask")
log.setLevel(Level.DEBUG)
 
def leavingUser = 'robgri' //Mitarbeiter der ersetzt werden soll!
def newUser = 'thogei' //Mitarbeiter der neu zugeteilt werden soll!
 
def jsonSlurper = new JsonSlurper()
 
def curl = "/usr/bin/curl -u admin:adminpass http://jira.oskar-ruegg.com/rest/api/2/project"
def output = curl.execute().text
def object = jsonSlurper.parseText(output)
String[] projectKeys = object.key
 
for (projectKey in projectKeys) {
    curl = "/usr/bin/curl -u admin:adminpass http://jira.oskar-ruegg.com/rest/api/2/project/" + projectKey + "/components"
    output = curl.execute().text
    object = jsonSlurper.parseText(output)
    for (component in object) {
        try {
            if (component.lead.name == leavingUser) {
                def jsonBody = "\"assigneeType\":\"COMPONENT_LEAD\", \"leadUserName\":\"" + newUser + "\", \"project\":\"" + projectKey + "\""
                def process = ["curl", "-u",  "admin:adminpass", "-X", "PUT", "--data", "{" + jsonBody + "}", "-H",  "Content-Type:application/json", "http://jira.oskar-ruegg.com/rest/api/2/component/" + component.id]
                output = process.execute().text
            }
        } catch (NullPointerException e) {}
         
    }
     
}

Hi @anon80600472, just a tip: maybe you could describe a little better what your actual problem is. It’s very unlikely that someone will just read your code and tell you what’s wrong. You should at least try to describe what you want to do, what isn’t working, what errors you’re seeing (if any) and what you have already tried so far.

Cheers,
Sven