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?
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 requests
from requests.auth import HTTPBasicAuth
# Jira credentials and base URL
jira_url = "https://your-jira-instance.com"
username = "your-username"
api_token = "your-api-token"
# Get all workflows
workflows_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 XML
export_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.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowManager
import com.opensymphony.workflow.loader.XMLWorkflowFactory
import java.nio.file.Files
import java.nio.file.Paths
// Directory where XML files will be saved
def exportDir = "/var/atlassian/application-data/jira/exported-workflows" // Update this path
// Ensure the directory exists
def exportPath = Paths.get(exportDir)
if (!Files.exists(exportPath)) {
Files.createDirectories(exportPath)
}
def workflowManager = ComponentAccessor.getComponent(WorkflowManager)
def xmlWorkflowFactory = new XMLWorkflowFactory()
// Iterate over all workflows
workflowManager.getWorkflows().each { workflow ->
def workflowName = workflow.getName()
try {
// Generate the XML content
def workflowXml = xmlWorkflowFactory.writeWorkflow(workflow)
// Save the XML to a file
def 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.
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}"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or you could just
SELECT descriptor FROM jiraworkflows
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.