Create a work item in Azure DevOps when an issue is created in Jira Cloud


Get Started

Not the template you're looking for? Browse more.

About the template


This template demonstrates how to create a workitem in Azure Devops when a new issue is created in Jira Cloud. It also adds a comment to the Jira issue with the work item id. Get started to learn more.

About ScriptRunner Connect


What is ScriptRunner Connect?

ScriptRunner Connect is an AI assisted code-first (JavaScript/TypeScript) integration platform (iPaaS) for building complex integrations and automations.

Can I try it out for free?

Yes. ScriptRunner Connect comes with a forever free tier.

Can I customize the integration logic?

Absolutely. The main value proposition of ScriptRunner Connect is that you'll get full access to the code that is powering the integration, which means you can make any changes to the the integration logic yourself.

Can I change the integration to communicate with additional apps?

Yes. Since ScriptRunner Connect specializes in enabling complex integrations, you can easily change the integration logic to connect to as many additional apps as you need, no limitations.

What if I don't feel comfortable making changes to the code?

First you can try out our AI assistant which can help you understand what the code does, and also help you make changes to the code. Alternatively you can hire our professionals to make the changes you need or build new integrations from scratch.

Do I have to host it myself?

No. ScriptRunner Connect is a fully managed SaaS (Software-as-a-Service) product.

What about security?

ScriptRunner Connect is ISO 27001 and SOC 2 certified. Learn more about our security.

Template Content


README

Scripts

TypeScriptOnJiraCloudIssueCreated
Issue Created

README


๐Ÿ“‹ Overview

This template demonstrates how to create a workitem in Azure Devops when a new issue is created in Jira Cloud. It also adds a comment to the Jira issue with the work item id.

๐Ÿ–Š๏ธ Setup

Set up the API connections and event listener for Jira Cloud and Azure DevOps. You can either create new connectors or use existing ones.

๐Ÿš€ Usage

Create a new issue in your Jira Cloud instance. Once the event is processed, a new work item will be created in Azure DevOps, and a comment containing the work item id will be added to the Jira issue.

API Connections


TypeScriptOnJiraCloudIssueCreated

import JiraCloud from './api/jira/cloud';
import AzureDevOps from './api/azure/devops';
import { IssueCreatedEvent } from '@sr-connect/jira-cloud/events';


/**
 * This function creates a workitem in Aure DevOps when an issue is created in Jira Cloud and then adds a comment withwork item number to the newly created issue
 *
 * @param event Object that holds Issue Created event data
 * @param context Object that holds function invocation context data
 */
export default async function (event: IssueCreatedEvent, context: Context): Promise<void> {
    if (context.triggerType === 'MANUAL') {
        console.error('This script is designed to be triggered externally or manually from the Event Listener. Please consider using Event Listener Test Event Payload if you need to trigger this script manually.');
        return;
    }

    const PROJECT_NAME = context.environment.vars['PROJECT_NAME'];
    const ORGANIZATION_NAME = context.environment.vars['ORGANIZATION_NAME'];
    const API_VERSION = context.environment.vars['API_VERSION'];
    const WORK_ITEM_TYPE = context.environment.vars['WORK_ITEM_TYPE'];

    try {
        // Create a new work item issue in Azure DevOps
        const workItemResponse = await AzureDevOps.fetch(`/${ORGANIZATION_NAME}/${PROJECT_NAME}/_apis/wit/workitems/${WORK_ITEM_TYPE}?api-version=${API_VERSION}`, {
            body: JSON.stringify(
                [
                    {
                        "op": "add",
                        "path": "/fields/System.Title",
                        "from": null,
                        "value": `${event.issue.key} created in Jira Cloud: ${event.issue.fields.summary}`
                    }
                ]
            ),
            method: 'POST',
            headers: {
                'Content-Type': 'application/json-patch+json'
            }
                
        });
        if (!workItemResponse.ok) {
            throw new Error(`Could not create work item. Fetch status ${workItemResponse.status}`);
        }
        
        const workItem = await workItemResponse.json();

        // Add a comment to the Issue that was created to include the incident number
        await JiraCloud.Issue.Comment.addComment({
            issueIdOrKey: event.issue.key,
            body: {
                body: {
                    type: 'doc',
                    version: 1,
                    content: [{
                        type: 'paragraph',
                        content: [{
                            type: 'text',
                            text: `Work item created with ID: ${workItem.id}`
                        }]
                    }]
                }
            }
        });
        console.log(`Work item created: ${workItem.id}`);

    } catch (e) {
        console.log('Error while processing event', e)
    }
}

Documentation ยท Support ยท Suggestions & feature requests