Jira is a project management and issue tracking tool provided by Atlassian.
It is widely used in software development for bug tracking, task management, and progress management.
MagicPod can integrate with CI tools such as GitHub Actions and with the Jira REST API to automatically create Jira issues (tickets) when tests fail during scheduled (batch) runs.
This page explains how to set this up.
(In this guide, we introduce how to integrate with GitHub Actions. If you are new to GitHub Actions integration, please refer to the Help page Integrate with GitHub Actions in advance.)
Prerequisites
In GitHub, go to Target Repository > Settings > Secrets and variables (Actions) > Repository secrets, and register the following values:
- MAGICPOD_API_TOKEN
- JIRA_URL
- JIRA_EMAIL
- JIRA_API_TOKEN
- JIRA_PROJECT_KEY
How to Obtain Each Repository Secret Value
-
MAGICPOD_API_TOKEN
Log in to MagicPod and copy your API token from this page.
-
JIRA_URL
Log in to Jira and check the browser address bar. Copy the following portion of the displayed URL:
https://<your_site_name>.atlassian.net
The <your_site_name> part is the site name (subdomain) that you set when you first created your Jira (Atlassian Cloud) site.
-
JIRA_EMAIL
Enter the email address of the Atlassian account you use to log in to Jira.
You can confirm this by clicking your profile icon in the top-right corner of Jira.
-
JIRA_API_TOKEN
While logged in to Jira, access this page and create an API token.
You can also access the same page from Account Settings > Security > Create and manage API tokens.
-
JIRA_PROJECT_KEY
The Jira project key is a unique identifier (a string of uppercase letters) assigned to each project. When you create an issue (ticket), it is displayed in the lower-left area of the ticket view.
In the example image below, the project key is "KAN".
Example Configuration File for GitHub Actions
Below is an example configuration file for browser testing. If you would like to create a configuration file for mobile app testing, please modify it accordingly based on the Help page Integrate with GitHub Actions.
Example Shell Script
Since the following SH file uses the jq command, please make sure that jq is available in your CI environment in advance. (macos-latest includes it by default, but in Linux environments, you may need to install it separately.)
SH file (run_magicpod_batch_with_jira_on_failure.sh)
#!/bin/bash -e
# With the -e option, the process exits immediately when a command fails.
# However, since MagicPod batch execution returns a non-zero exit code when tests fail,
# we temporarily disable automatic exit using set +e only for that section and handle the exit code manually.
OS=mac # Specify the OS (change if using Windows or Linux)
FILENAME=magicpod-api-client # Arbitrary file name
curl -L "https://app.magicpod.com/api/v1.0/magicpod-clients/api/${OS}/latest/" -H "Authorization: Token ${MAGICPOD_API_TOKEN}" --output ${FILENAME}.zip
unzip -q ${FILENAME}.zip
# Set environment variables used by MagicPod
export MAGICPOD_ORGANIZATION=<MagicPod organization name>
export MAGICPOD_PROJECT=<MagicPod project name>
# Specify the batch run setting number and execute batch run via magicpod-api-client
set +e # Temporarily disable automatic exit to capture exit code even if tests fail
TEST_SETTING_NUMBER=<Batch run setting number>
./magicpod-api-client batch-run -S ${TEST_SETTING_NUMBER}
EXIT_CODE=$?
set -e # Re-enable automatic exit
echo ""
echo "=== Test Results ==="
# If tests succeed, exit the process.
# If tests fail, create Jira issues.
if [ ${EXIT_CODE} -ne 0 ]; then
echo "Tests did not succeed. Creating Jira Issues. (exit code: ${EXIT_CODE})"
echo ""
echo "=== Creating Jira Issues for Failed Tests ==="
# Retrieve the latest batch run number
LATEST_BATCH_RUN_INFO=$(curl -s -X GET \
"https://app.magicpod.com/api/v1.0/${MAGICPOD_ORGANIZATION}/${MAGICPOD_PROJECT}/batch-runs/?count=1&max_batch_run_number=50000" \
-H "accept: application/json" \
-H "Authorization: Token ${MAGICPOD_API_TOKEN}")
LATEST_BATCH_RUN_NUMBER=$(echo "${LATEST_BATCH_RUN_INFO}" | jq -r '.batch_runs[0].batch_run_number // empty')
if [ -z "${LATEST_BATCH_RUN_NUMBER}" ]; then
echo "Error: Failed to retrieve batch run number"
exit 1
fi
echo "Batch run number: ${LATEST_BATCH_RUN_NUMBER}"
# Retrieve details for the batch run
BATCH_RUN_DETAILS=$(curl -s -X GET \
"https://app.magicpod.com/api/v1.0/${MAGICPOD_ORGANIZATION}/${MAGICPOD_PROJECT}/batch-run/${LATEST_BATCH_RUN_NUMBER}/" \
-H "accept: application/json" \
-H "Authorization: Token ${MAGICPOD_API_TOKEN}")
# Retrieve failed test case numbers
FAILED_TESTS=$(echo "${BATCH_RUN_DETAILS}" | jq -r '
.test_cases.details[].results[] |
select(.status == "failed" or .status == "unresolved") |
.test_case.number
' | sort -u)
if [ -z "${FAILED_TESTS}" ]; then
echo "No failed tests found"
exit 0
fi
echo "=== Failed Tests Detected ==="
# Create a Jira Issue via Jira REST API for each failed test
for TEST_NUM in ${FAILED_TESTS}; do
echo "Creating issue for Test Case #${TEST_NUM}..."
RESULT_URL="https://app.magicpod.com/${MAGICPOD_ORGANIZATION}/${MAGICPOD_PROJECT}/batch-run/${LATEST_BATCH_RUN_NUMBER}/"
set +e # Temporarily disable automatic exit to capture exit code even if tests fail
JIRA_RESPONSE=$(curl -s -L -w "\n%{http_code}" -X POST "${JIRA_URL}/rest/api/3/issue" \
-u "${JIRA_EMAIL}:${JIRA_API_TOKEN}" \
-H "Content-Type: application/json" \
-d "{
\"fields\": {
\"project\": {\"key\": \"${JIRA_PROJECT_KEY}\"},
\"summary\": \"[MagicPod] Test Failure: #${TEST_NUM}\",
\"description\": {
\"type\": \"doc\",
\"version\": 1,
\"content\": [
{
\"type\": \"paragraph\",
\"content\": [
{
\"type\": \"text\",
\"text\": \"Test case #${TEST_NUM} failed in batch run #${LATEST_BATCH_RUN_NUMBER}.\"
}
]
},
{
\"type\": \"paragraph\",
\"content\": [
{
\"type\": \"text\",
\"text\": \"Result URL: \",
\"marks\": [{\"type\": \"strong\"}]
},
{
\"type\": \"text\",
\"text\": \"${RESULT_URL}\",
\"marks\": [{
\"type\": \"link\",
\"attrs\": {\"href\": \"${RESULT_URL}\"}
}]
}
]
}
]
},
\"issuetype\": {\"name\": \"Task\"},
\"labels\": [\"magicpod\", \"test-failure\"]
}
}")
set -e # Re-enable automatic exit
HTTP_CODE=$(echo "${JIRA_RESPONSE}" | tail -n1)
RESPONSE_BODY=$(echo "${JIRA_RESPONSE}" | sed '$d')
if [ "${HTTP_CODE}" = "201" ]; then
ISSUE_KEY=$(echo "${RESPONSE_BODY}" | jq -r '.key // empty')
echo "✓ Issue successfully created: ${ISSUE_KEY}"
else
echo "✗ Failed to create issue (HTTP ${HTTP_CODE})"
fi
done
echo ""
echo "=== Completed ==="
echo "Jira Issues have been created."
exit 0
else
echo "✓ Tests succeeded."
exit 0
fi
Example Workflow Configuration File (YML)
YML file
# Run this workflow when pushing
on: [push]
# For manual execution, comment out the above "on: [push]" and uncomment the line below
# on: workflow_dispatch
jobs:
# Job name (arbitrary)
magic_pod_job:
# Specify virtual machine type
runs-on: macos-latest # macOS specified in this example
# Steps within the job
steps:
# Step 1 (Checkout)
- name: Checkout
uses: actions/checkout@v3 # Specify the latest version
# Step 2 (Run batch test in MagicPod and create Jira issues if failed)
- name: Batch run test (create Jira issue if failed)
# Reference values registered in Repository secrets
env:
MAGICPOD_API_TOKEN: ${{ secrets.MAGICPOD_API_TOKEN }}
JIRA_URL: ${{ secrets.JIRA_URL }}
JIRA_EMAIL: ${{ secrets.JIRA_EMAIL }}
JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
JIRA_PROJECT_KEY: ${{ secrets.JIRA_PROJECT_KEY }}
# Specify the created shell script file name
run: |
bash run_magicpod_batch_with_jira_on_failure.sh
By executing the above configuration example, you can create Jira issues (tickets) containing the following:
A URL that allows navigation to the failed test result screen
Issue type set to "Task"
Labels "magicpod" and "test-failure" added
In addition to the issue type and labels specified in the above example, you can also set fields such as priority and assignee.
# To specify priority
\"priority\": {\"name\": \"High\"}
# To specify assignee
\"assignee\": {\"id\": \"<account_id>\"}For further detailed configuration options, please refer to the official Jira REST API documentation: