Install Cypress Test Results from the Atlassian Marketplace.
Create cypress-jira-reporter.js in your project root:
// cypress-jira-reporter.js
const Mocha = require('mocha');
const { EVENT_RUN_END, EVENT_TEST_PASS, EVENT_TEST_FAIL, EVENT_TEST_PENDING } = Mocha.Runner.constants;
class JiraReporter extends Mocha.reporters.Base {
constructor(runner, options) {
super(runner);
const reporterOptions = options.reporterOptions || {};
const issueId = reporterOptions.issueId || process.env.JIRA_ISSUE_ID;
const webhookUrl = reporterOptions.webhookUrl || process.env.JIRA_WEBHOOK_URL;
const token = reporterOptions.token || process.env.JIRA_WEBHOOK_TOKEN;
const stats = { passed: 0, failed: 0, skipped: 0, duration: 0 };
const tests = [];
runner.on(EVENT_TEST_PASS, (test) => {
stats.passed++;
tests.push({ title: test.title, status: 'passed', duration: test.duration || 0 });
});
runner.on(EVENT_TEST_FAIL, (test) => {
stats.failed++;
tests.push({ title: test.title, status: 'failed', duration: test.duration || 0 });
});
runner.on(EVENT_TEST_PENDING, (test) => {
stats.skipped++;
tests.push({ title: test.title, status: 'skipped', duration: 0 });
});
runner.on(EVENT_RUN_END, async () => {
stats.duration = Date.now() - this.startTime;
const overallStatus = stats.failed > 0 ? 'failed' : 'passed';
const payload = {
token: token,
issueId: issueId,
status: overallStatus,
summary: stats,
tests: tests
};
if (!webhookUrl || !token || !issueId) {
console.warn('\\n[Jira Reporter] ⚠️ Missing Webhook URL, Token, or Issue ID. Skipping Jira update.');
return;
}
console.log('\\n[Jira Reporter] Sending results to Jira issue:', issueId);
try {
await fetch(webhookUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
console.log('[Jira Reporter] ✅ Successfully pushed results to Jira!');
} catch (e) {
console.error('[Jira Reporter] ❌ Error sending payload to Jira:', e);
}
});
this.startTime = Date.now();
}
}
module.exports = JiraReporter;
(Important: Please ensure issueId is the numeric ID, e.g., 10023, not the Key like PROJ-1 )
How to find the Numeric Issue ID:
...&selectedIssue=10023. The number is the ID.— If you are in the direct issue view: You can navigate to Jira ticket → click ‘Actions’ button → click ‘Export XML’ → copy value of ‘key_id’, i.e. <key id=”10134">KAN-7</key> (here you’ll need to copy 10134)Press enter or click to view image in full size
Press enter or click to view image in full size