cloud_console_getAllProjects
Fri Nov 15 2024 20:18:16 GMT+0000 (Coordinated Universal Time)
Saved by
@belleJar
#groovy
// Call the Jira REST API to retrieve all projects
def response = get('/rest/api/3/project')
.header('Content-Type', 'application/json')
.asObject(List)
// Check for a successful response
if (response.status != 200) {
return "Error fetching projects: ${response.status} - ${response.statusText}"
}
// Cast the response body to a List of Maps for static type checking
List<Map> projects = response.body as List<Map>
// Extract project data and map to a simplified structure
return projects.collect { project ->
[
id : project['id'],
key : project['key'],
name : project['name']
]
}
content_copyCOPY
directly access "ComponentAccessor" (as supposed to DC), Rest API with SR or javaScript/ Type Script cast response.body to a list<map> for proper handling.
Logic:
API Endpoint: The script calls /rest/api/3/project, which retrieves all projects in Jira Cloud.
fetch API: Used to make REST API calls.
Error Handling: Errors are caught and logged for better debugging.
Mapping: The returned project data is formatted into a simplified array of objects with id, key, and name.
Comments