Hi Team,
Is there any script to fetch list of all the Issue types Schemes and issue types for whole Jira instance?
Regards,
Anuradha
Hi Anuradha,
Below is the script to get the output. I've defined other schemes as well and you can use whatever you need.
Please mark the answer as accepted if it solves your request.
import com.atlassian.jira.component.ComponentAccessorimport org.apache.log4j.Categorydef loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")log.setLevel(org.apache.log4j.Level.DEBUG)def issueTypeSchemeManager = ComponentAccessor.getIssueTypeSchemeManager()def wrkflwScheme = ComponentAccessor.getWorkflowSchemeManager()def issueTypeScreenSchemeManager=ComponentAccessor.getIssueTypeScreenSchemeManager()def issueTypeScreenScheme = ComponentAccessor.getIssueTypeScreenSchemeManager()def fieldScheme = ComponentAccessor.getFieldLayoutManager()def wrkflw = ComponentAccessor.getWorkflowManager()def issueType = ComponentAccessor.getIssueTypeSchemeManager()log.info(issueTypeScreenSchemeManager.getIssueTypeScreenSchemes()*.name)log.info(issueType.getAllSchemes()*.name)
Thanks,Aditya
Thanks it works! But I wanted a excel sheet where the list has How many issues have particular issue type, project key (name), project lead.?
Something like below?
th("issuetype") th("Issue Count") th("Issuetype scheme") th("Project Count") th("Project Key") th("Project Name") th("Project Lead") th("Project Lead Emails")
I have script from my team but as I am new with groovy / scrip runner and I am having difficulties in writing/modifying a script
Script below works, but want to modify to fetch data about issue types and issue type schemes:
import com.atlassian.jira.bc.JiraServiceContextimport com.atlassian.jira.bc.JiraServiceContextImplimport com.atlassian.jira.bc.filter.SearchRequestServiceimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.config.ConstantsManagerimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.index.IssueIndexingServiceimport com.atlassian.jira.issue.search.SearchRequestimport com.atlassian.jira.issue.search.SearchResultsimport com.atlassian.jira.issue.status.Statusimport com.atlassian.jira.mail.Emailimport com.atlassian.jira.mail.settings.MailSettingsimport com.atlassian.jira.project.Projectimport com.atlassian.jira.project.ProjectManagerimport com.atlassian.jira.scheme.SchemeManagerimport com.atlassian.jira.security.JiraAuthenticationContextimport com.atlassian.jira.util.ImportUtilsimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.workflow.AssignableWorkflowSchemeimport com.atlassian.jira.workflow.JiraWorkflowimport com.atlassian.jira.workflow.WorkflowManagerimport com.atlassian.jira.workflow.WorkflowSchemeManagerimport com.atlassian.mail.MailExceptionimport com.atlassian.mail.server.SMTPMailServerimport com.atlassian.plugin.util.ContextClassLoaderSwitchingUtilimport com.onresolve.scriptrunner.canned.CannedScriptimport com.onresolve.scriptrunner.canned.jira.utils.CannedScriptUtilsimport com.onresolve.scriptrunner.canned.util.BuiltinScriptErrorsimport com.onresolve.scriptrunner.canned.util.SimpleBuiltinScriptErrorsimport groovy.xml.MarkupBuilderimport org.apache.log4j.Loggerimport com.atlassian.jira.config.StatusManager
import javax.activation.DataHandlerimport javax.activation.FileDataSourceimport javax.mail.MessagingExceptionimport javax.mail.Multipartimport javax.mail.internet.MimeBodyPartimport javax.mail.internet.MimeMultipartimport java.sql.Timestampimport java.text.SimpleDateFormat
JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext()ProjectManager projectManager = ComponentAccessor.getProjectManager()WorkflowSchemeManager workflowSchemeManager = ComponentAccessor.getWorkflowSchemeManager()WorkflowManager workflowManager = ComponentAccessor.getWorkflowManager()StatusManager statusManager = ComponentAccessor.getComponentOfType(StatusManager.class)IssueManager issueManager = ComponentAccessor.getIssueManager()
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm")
//All projectsList<Project> projects = new ArrayList<>()projects.addAll(projectManager.getProjects())
//All issuesList<String> issueStatuses = new ArrayList<>()for (Project project : projects) { Collection<Long> issueIds = issueManager.getIssueIdsForProject(project.id) for (Long issueId : issueIds) { Issue issue = issueManager.getIssueObject(issueId) issueStatuses.add(issue.status.name) }}
//All workflowsCollection<JiraWorkflow> allWorkflows = new ArrayList<>()allWorkflows = workflowManager.getWorkflows()List<JiraWorkflow> activeWorkflows = new ArrayList<>()List<JiraWorkflow> inactiveWorkflows = new ArrayList<>()for (JiraWorkflow workflow : allWorkflows) { if(workflow.isActive() == true){ activeWorkflows.add(workflow) } else { inactiveWorkflows.add(workflow) }}
//All statusesList<Status> statuses = new ArrayList<>()statuses.addAll(statusManager.getStatuses())
def writer = new StringWriter()def xml = new MarkupBuilder(writer)xml.table(){ tr{ th("Status") th("Issue Count") th("Workflow Count") th("Active Workflows") th("Inactive Workflows") th("Project Count") th("Project Key") th("Project Name") th("Project Lead") th("Project Lead Emails") } for (Status status : statuses) { tr{ td(status.name) // Status Name td(issueStatuses.count(status.name)) // Issue Count def activeLinkedWorkflows = [] def inactiveLinkedWorkflows = [] for (JiraWorkflow workflow : activeWorkflows) { if (workflow.getLinkedStatusObjects()*.id.contains(status.getId())) { activeLinkedWorkflows.add(workflow.name) } } for (JiraWorkflow workflow : inactiveWorkflows) { if (workflow.getLinkedStatusObjects()*.id.contains(status.getId())) { inactiveLinkedWorkflows.add(workflow.name) } } td(activeLinkedWorkflows.size() + inactiveLinkedWorkflows.size()) // Count td(activeLinkedWorkflows.toString())// Active td(inactiveLinkedWorkflows.toString()) // Inactive def linkedProjects = [] def linkedProjectLeads = [] def linkedProjectLeadEmails = [] projects.each { project -> def scheme = workflowSchemeManager.getWorkflowScheme(project) def wfs = workflowManager.getWorkflowsFromScheme(scheme)*.name wfs.each{wf -> if(activeLinkedWorkflows.contains(wf)){ linkedProjects.add(project) } }
} linkedProjects.unique() linkedProjects.each { project -> linkedProjectLeads.add(project.lead.getDisplayName()) linkedProjectLeadEmails.add(project.lead.getEmailAddress()) } td(linkedProjects.size()) // Project Count td(linkedProjects.key.toString())// Project Key td(linkedProjects.name.toString())// Project Name td(linkedProjectLeads.toString())// Project Leads td(linkedProjectLeadEmails.toString())// Project Lead Emails } }}
writer.toString()
private static Boolean sendEmail(String emailAddr, String subject, String body, StringWriter attachmentData) { MailSettings mailSettings = ComponentAccessor.getComponent(MailSettings) if (mailSettings?.send()?.disabled) { return false } SMTPMailServer mailServer = ComponentAccessor.mailServerManager.defaultSMTPMailServer if (!mailServer) { return false }
Email email = new Email(emailAddr) email.setMimeType('text/html') email.setSubject(subject) email.setBody(body)
String fileName = "/tmp/${System.currentTimeMillis().toString()}_status_information.html" File myFile = new File(fileName) myFile << attachmentData.toString() Multipart multipart = new MimeMultipart("mixed") MimeBodyPart attachPart = new MimeBodyPart() File csvFile = new File(fileName) FileDataSource source = new FileDataSource(csvFile) attachPart.setDataHandler(new DataHandler(source)) attachPart.setFileName(csvFile.getName()) multipart.addBodyPart(attachPart) email.setMultipart(multipart)
try { ContextClassLoaderSwitchingUtil.runInContext(SMTPMailServer.classLoader) { mailServer.send(email) } return true } catch (MailException e) { return false }}
sendEmail(authenticationContext.getLoggedInUser().getEmailAddress(), "Status Overview", "Please find the results attached.", writer)
Can you please modify script to fetch below details in excel:
Hi, @[deleted],
Could you please update?
It looks like you're new here. Sign in or register to get started.