Работа с конфигуратором проекта и ScriptRunner для Jira асинхронный экспорт - malikovalibek/groovyForJira GitHub Wiki
Конфигуратор проекта может выполнять большинство операций в двух режимах: асинхронном и синхронном. Асинхронный режим - это то, что видят большинство конечных пользователей, операция запускается в фоновом потоке, вы можете запросить ее ход (например, чтобы отобразить индикатор выполнения), и когда он будет завершен, можно получить результаты операции и сделай что-нибудь с ними. Это уместно, когда операция будет выполняться долго, обычно потому, что экспорт / импорт подразумевает большие объемы конфигурации и данных. В противном случае, если большинство ваших операций будет выполняться в течение ограниченного времени, вы можете просто использовать синхронные методы.
С участием ScriptRunner для Jira от Adaptavist
Конфигуратор проекта от Adaptavist
Создано 2 года назад , Обновлено 5 месяцев назад
Код сервера Код центра обработки данных
Требования
import com.atlassian.jira.component.ComponentAccessor import com.awnaba.projectconfigurator.operationsapi.ExportResult import com.awnaba.projectconfigurator.operationsapi.ProjectConfigExporter import com.awnaba.projectconfigurator.operationsapi.TaskHelper import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import static com.onresolve.scriptrunner.canned.util.OutputFormatter.markupBuilder
// The required annotation to enable access to the functionality provided by the plugin within our script. @WithPlugin("com.awnaba.projectconfigurator.projectconfigurator")
// Define our Asynchronous Exporter Class class AsynchronusExporter {
// Define our export method
String export() {
// Get an instance of the export method
def exporter = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectConfigExporter)
// Define a set to store the keys of all of the projects that we wish to export
def projectKeys = [] as Set
// Add the project keys that we want to export to our projectKeys set
projectKeys.add("DEMO")
projectKeys.add("DEMO1")
// Define a map to store all of the export options that we require
// Add values to our exportOptions map
def exportOptions = [
// Options: none, filterUnusedCFExtended, all
filterCFMode : "filterUnusedCFExtended",
// Options: none, global, projects, global-or-projects, shared, all
jiraFilterExportMode : "none",
// Options: none, global, projects, global-or-projects, shared, all
jiraDashboardExportMode: "none",
// Options: none, projects, all
agileBoardsExportMode : "none"
]
// Try to generate the export safely throwing an exception if generating the export fails.
try {
// Call the asynchronous export method passing in the export options map and the project keys set as parameters
def exportResult = exporter.export(exportOptions, projectKeys)
// Check if the export completed successfully and if so generate the XML file
// If the export failed notify the user
// Possible return codes that can be checked = EXPORT_STARTED, NOT_LOGGED_IN, UNAUTHORIZED, UNLICENSED, NO_PROJECTS, EXPORT_ALREADY_RUNNING
if (exportResult.returnCode.toString() != "EXPORT_STARTED") {
return "The export did not start successfully with a return code of " + exportResult.returnCode.toString()
}
// 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
def exportFile = "/tmp/export.xml"
// Get the task ID of of the export from the Config Op Call Result object
def taskId = exportResult.taskId
//Get a new instance of the task helper class
def taskHelper = ComponentAccessor.getOSGiComponentInstanceOfType(TaskHelper)
// Get the task descriptor object for the current task provided by the task helper class
def taskDescriptor = taskHelper.getTaskState(taskId)
// Wait until the export task is finished
while (!taskDescriptor?.isFinished()) {
// Wait 0.5 seconds before getting a new instance of the taskDescriptor
sleep(500)
// Get a new instance of the task descriptor
taskDescriptor = taskHelper.getTaskState(taskId)
}
new File(exportFile).text = ((ExportResult) taskHelper.getResult(taskDescriptor)).exportedFile.toString()
"Export file created at " + exportFile
// Throw an exception if the XML export file cannot be generated
} catch (IOException e) {
markupBuilder {
p("An unexpected error occurred. Please check your atlassian-jira.log for more information")
p(e)
}
}
}
} // Call the export method from the script console new AsynchronusExporter().export()