Groovy examples
What’s new?
From version 3.3.1, the method getExportedFile
 from the interface ExportResult
 is deprecated. The method getExportedReturnFile
 should be used instead. This new method returns the export configuration file directly, so it is no longer necessary to write the XML string to a file.
Synchronous export example version 3.3.1 or newer
This example has a simple approach to error handling.
synchronous-export-example.groovy (v 3.3.1 or newer)
// Required Imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.task.TaskProgressSink
import com.awnaba.projectconfigurator.operationsapi.ProjectConfigExporter
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.awnaba.projectconfigurator.operationsapi.ConfigOpFullProcessResult
import com.awnaba.projectconfigurator.operationsapi.ReturnCode
// The required annotation to enable access to the functionality provided by the plugin within our script.
@WithPlugin("com.awnaba.projectconfigurator.projectconfigurator")
// Get an instance of the export method
ProjectConfigExporter exporter = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectConfigExporter)
try {
// Define the project keys to be exported in the set below
Set<String> projectKeys = ["DEMO", "OTHER"].toSet()
// Define the options for how you want to configure the export.
Map<String, String> exportOptions = [
"filterCFMode" : "filterUnusedCFExtended", // Options: none, filterUnusedCFExtended, all
"jiraFilterExportMode" : "none", // Options: none, global, projects, global-or-projects, shared, all
"jiraDashboardExportMode": "none", // Options: none, global, projects, global-or-projects, shared, all
"agileBoardsExportMode" : "none", // Options: none, projects, all
"fileName" : "fileName"
]
// Run the export synchronously using the options specified above
ConfigOpFullProcessResult export = exporter.exportSynchronous(exportOptions, projectKeys, TaskProgressSink.NULL_SINK);
def exportFinalResult = export.getFinalResult()
def exportCall = export.getCallResult()
// Check if the export completed successfully and if so generate the XML file
// If the export failed notify the user
if (exportFinalResult == null || exportFinalResult.getReturnCode() != ProjectConfigExporter.ReturnOpCode.SUCCESS) {
return "The export did not complete successfully: " + exportFinalResult == null ? exportCall.getReturnCode() : exportFinalResult.getReturnCode()
} else {
// If the export was successful notify the user where the file is stored
return "Export file created at " + exportFinalResult.getExportedResultFile().toPath()
}
} catch (Exception e) {
return "An unexpected error occurred. Please check your atlassian-jira.log for more information" + "<br/>" + e
}
Synchronous export example version 3.0.5 or newer
From 3.0.4 to 3.0.5: method getExportedXML
 from FinalResult
 object is now called getExportedFile
 to unify interface ExportResult
. This example has a simple approach to error handling.
synchronous-export-example.groovy (v 3.0.5 or newer)
// Required Imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.task.TaskProgressSink
import com.awnaba.projectconfigurator.operationsapi.ProjectConfigExporter
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.awnaba.projectconfigurator.operationsapi.ConfigOpFullProcessResult
import com.awnaba.projectconfigurator.operationsapi.ReturnCode
// The required annotation to enable access to the functionality provided by the plugin within our script.
@WithPlugin("com.awnaba.projectconfigurator.projectconfigurator")
// Get an instance of the export method
ProjectConfigExporter exporter = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectConfigExporter)
try {
// Define the project keys to be exported in the set below
Set<String> projectKeys = ["DEMO", "OTHER"].toSet()
// Define the options for how you want to configure the export.
Map<String, String> exportOptions = [
"filterCFMode" : "filterUnusedCFExtended", // Options: none, filterUnusedCFExtended, all
"jiraFilterExportMode" : "none", // Options: none, global, projects, global-or-projects, shared, all
"jiraDashboardExportMode": "none", // Options: none, global, projects, global-or-projects, shared, all
"agileBoardsExportMode" : "none" // Options: none, projects, all
]
// Run the export synchronously using the options specified above
ConfigOpFullProcessResult export = exporter.exportSynchronous(exportOptions, projectKeys, TaskProgressSink.NULL_SINK);
def exportFinalResult = export.getFinalResult()
def exportCall = export.getCallResult()
// Check if the export completed successfully and if so generate the XML file
// If the export failed notify the user
if (exportFinalResult == null || exportFinalResult.getReturnCode() != ProjectConfigExporter.ReturnOpCode.SUCCESS) {
return "The export did not complete successfully: " + exportFinalResult == null ? exportCall.getReturnCode() : exportFinalResult.getReturnCode()
} else {
// If the export was successful write the XML out to a file and notify the user where the file is stored
// Define the path and export filename to be used below
File exportFile = new File("/tmp/export.xml")
// Write the generated xml out to a configuration export XML file.
exportFile.write(exportFinalResult.getExportedFile().toString())
// Return the location to the created export file
return "Export file created at " + exportFile
}
} catch (Exception e) {
return "An unexpected error occurred. Please check your atlassian-jira.log for more information" + "<br/>" + e
}
Synchronous export example version 3.0.4 or older
This example has a single approach to error handling.
synchronous-export-example.groovy (v 3.0.4 or older)
// Required Imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.task.TaskProgressSink
import com.awnaba.projectconfigurator.operationsapi.ProjectConfigExporter
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
// The required annotation to enable access to the functionality provided by the plugin within our script.
@WithPlugin("com.awnaba.projectconfigurator.projectconfigurator")
// Get an instance of the export method
ProjectConfigExporter exporter = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectConfigExporter)
try {
// Define the project keys to be exported in the set below
Set projectKeys = ["DEMO", "DEMO1"]
// Define the options for how you want to configure the export.
Map<String, String> exportOptions = [
"filterCFMode" : "filterUnusedCFExtended", // Options: none, filterUnusedCFExtended, all
"jiraFilterExportMode" : "none", // Options: none, global, projects, global-or-projects, shared, all
"jiraDashboardExportMode": "none", // Options: none, global, projects, global-or-projects, shared, all
"agileBoardsExportMode" : "none" // Options: none, projects, all
]
// Run the export synchronously using the options specified above
def exportFinalResult = exporter.exportSynchronous(exportOptions, projectKeys, TaskProgressSink.NULL_SINK).getFinalResult()
// Check if the export completed successfully and if so generate the XML file
// If the export failed notify the user
if (exportFinalResult == null || exportFinalResult.getReturnCode() != ProjectConfigExporter.ReturnOpCode.SUCCESS) {
return "The export did not complete successfully"
} else {
// If the export was successful write the XML out to a file and notify the user where the file is stored
// Define the path and export filename to be used below
File exportFile = new File("/tmp/export.xml")
// Write the generated xml out to a configuration export XML file.
exportFile.write(exportFinalResult.getExportedXML())
// Return the location to the created export file
return "Export file created at " + exportFile
}
} catch (Exception e) {
return "An unexpected error occurred. Please check your atlassian-jira.log for more information" + "<br/>" + e
}
Synchronous import example
synchronous-import-example.groovy (all versions)