Hi Team,
usually, I would go to the list of workflows page
next click on View workflow
next click on export as XML
Is there any way to bulk this operation for all workflows?
Hi @Chamdarig Dall
It's not possible bulk export the workflows native in jira, but you can use jira api to automatically save them locally with python.
import requestsfrom requests.auth import HTTPBasicAuth# Jira credentials and base URLjira_url = "https://your-jira-instance.com"username = "your-username"api_token = "your-api-token"# Get all workflowsworkflows_endpoint = f"{jira_url}/rest/api/2/workflow"response = requests.get(workflows_endpoint, auth=HTTPBasicAuth(username, api_token))if response.status_code == 200:workflows = response.json()for workflow in workflows:workflow_name = workflow['name']print(f"Exporting workflow: {workflow_name}")# Export workflow XMLexport_url = f"{jira_url}/secure/admin/workflows/ViewXml.jspa?workflowMode=live&workflowName={workflow_name}"export_response = requests.get(export_url, auth=HTTPBasicAuth(username, api_token))if export_response.status_code == 200:with open(f"{workflow_name}.xml", "w") as file:file.write(export_response.text)else:print(f"Failed to export workflow: {workflow_name} - {export_response.status_code}")else:print(f"Failed to fetch workflows: {response.status_code}")
You can also make this directy in Jira with scriptrunner, but you will need acess in the server to download them to your local.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.workflow.WorkflowManagerimport com.opensymphony.workflow.loader.XMLWorkflowFactoryimport java.nio.file.Filesimport java.nio.file.Paths// Directory where XML files will be saveddef exportDir = "/var/atlassian/application-data/jira/exported-workflows" // Update this path// Ensure the directory existsdef exportPath = Paths.get(exportDir)if (!Files.exists(exportPath)) {Files.createDirectories(exportPath)}def workflowManager = ComponentAccessor.getComponent(WorkflowManager)def xmlWorkflowFactory = new XMLWorkflowFactory()// Iterate over all workflowsworkflowManager.getWorkflows().each { workflow ->def workflowName = workflow.getName()try {// Generate the XML contentdef workflowXml = xmlWorkflowFactory.writeWorkflow(workflow)// Save the XML to a filedef workflowFile = Paths.get(exportDir, "${workflowName}.xml")Files.write(workflowFile, workflowXml.bytes)log.info("Exported workflow: ${workflowName} to ${workflowFile}")} catch (Exception e) {log.error("Failed to export workflow: ${workflowName}", e)}}log.info("All workflows exported to ${exportDir}")
This script you run in the Scriptrunner Console and have to ensure the necessary permissions to write and read in the target path.Let me know if this helps you.
Best Regards.
I do not have the script anymore but I find this. You should be able to go through every workflow in a script, for each workflow get the workflow descriptor using the java api.
Then you can convert descriptor to xml based on this doc.
Regards
Or you could just
SELECT descriptor FROM jiraworkflows
Hey thanks! This Python script had just what I was looking for. Except... I needed it for Cloud.
Luckily I think it will work with this one minor change:
export_url = f"{jira_url}/secure/admin/workflows/ViewWorkflowXml.jspa?workflowMode=live&workflowName={workflow_name}"
It looks like you're new here. Sign in or register to get started.