Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Bulk export all Jira workflows as xml files

Chamdarig Dall January 10, 2025

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?

3 answers

1 vote
Kawan Diogo
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2025

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 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.

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2025

Or you could just

SELECT descriptor FROM jiraworkflows

 

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 10, 2025

Hi @Chamdarig Dall 

 

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

Suggest an answer

Log in or Sign up to answer