Im trying to bulk move issues in Jira cloud using script runner. I created a script to move the issues but they are not actually moving even though my logs say they were successfully moved.
def targetProjectKey = "AT2"
def issueKeys = ["AT1-12", "AT1-13","AT1-15","AT1-16","AT1-17"]
// Initialize the logger
logger.info("Starting bulk move of issues to project: ${targetProjectKey}")
// Function to get issue details
def getIssueDetails(issueKey) {
def issue = get('/rest/api/3/search')
.queryString('jql', "project = 'AT1'")
.queryString("expand", "key")
.asObject(Map)
if (!issue) {
logger.error("Issue ${issueKey} not found")
return null
}
return [
key: issue.body.key,
id: issue.body.id,
typeId: issue.body.issueTypeId,
//summary: issue.body.summary
]
}
// Function to move an issue using REST API
def moveIssueToProject(issueKey, targetProjectKey) {
logger.info("Moving issue ${issueKey} to project ${targetProjectKey}")
try {
// Get issue details first
def issueDetails = getIssueDetails(issueKey)
if (!issueDetails) {
return [success: false, message: "Issue not found"]
}
// Prepare request body
def requestBody = [
fields: [
project: [
key: targetProjectKey
]
]
]
// Make REST API call to update the issue
def response = put("/rest/api/2/issue/${issueKey}")
.header("Content-Type", "application/json")
.body(requestBody)
.asJson()
if (response.status == 204 || response.status == 200) {
logger.info("Successfully moved issue ${issueKey} to project ${targetProjectKey}")
return [success: true, message: "Successfully moved issue"]
} else {
logger.error("Failed to move issue ${issueKey}. Status: ${response.status}, Body: ${response.body}")
return [success: false, message: "Failed to move issue: ${response.body}"]
}
} catch (Exception e) {
logger.error("Exception while moving issue ${issueKey}: ${e.message}")
return [success: false, message: "Exception: ${e.message}"]
}
}
// Main execution
def results = []
// Process issues in the specified order
issueKeys.each { issueKey ->
def result = moveIssueToProject(issueKey, targetProjectKey)
results.add([issueKey: issueKey, result: result])
// Add a small delay to prevent rate limiting
sleep(500)
}
// Return results
return results
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.