Stages Jira Cloud Scripting Documentation
    Preparing search index...

    Stages Jira Cloud Scripting Documentation

    Welcome to the Jira Cloud Execution scripting documentation. Here you can find the two main interfaces to implement in your Stages execution scripts:

    The function executeActivator is triggered when a user clicks the coresponding execute button in Stages.

    In this example we create a REST request to create a Jira issue and receive back a response with information about the result. In this case the result is a link to the issue which is displayed in Stages.

    async function executeActivator(activation, jiraContext) {
    const projectKey = jiraContext.getProjectKey();
    const elementFieldId = jiraContext.getElementFieldId();
    const enactedElement = activation.getEnactedProcessElement();
    const body = {
    "fields": {
    "description": {
    "content": [
    {
    "content": [
    {
    "text": "",
    "type": "text"
    }
    ],
    "type": "paragraph"
    }
    ],
    "type": "doc",
    "version": 1
    },
    "project": {
    "key": projectKey
    },
    "issuetype": {
    "name": "Task"
    },
    "summary": activation.getTitle(),
    [elementFieldId]: enactedElement.getId()
    }
    };

    const response = await fetchJira("POST", "/rest/api/3/issue", body);

    const activationSummary = {
    status: "SUCCESS",
    message: response.key,
    url: jiraContext.getBaseUrl() + "/browse/" + response.key
    }

    return ActivationResultFactory.createActivationResult(activationSummary, undefined);
    }

    The function post is triggered if there is a change on a Jira issues that is automated by Stages. Typically this is a change in the issue state.

    async function post(workflow, jiraContext) {
    const enactedElement = workflow.getEnactedProcessElement();
    const children = enactedElement.getChildren();
    const elementFieldId = jiraContext.getElementFieldId();

    // For example create sub tasks:
    for (const child of children) {
    const body = {
    "fields": {
    "description": {
    "content": [
    {
    "content": [
    {
    "text": "",
    "type": "text"
    }
    ],
    "type": "paragraph"
    }
    ],
    "type": "doc",
    "version": 1
    },
    "project": {
    "key": jiraContext.getProjectKey(),
    },
    "issuetype": {
    "name": "Sub-task"
    },
    "summary": child.getName(),
    "parent": {
    "key": jiraContext.getIssueKey()
    },
    [elementFieldId]: child.getId()
    }
    };

    await fetchJira("POST", "/rest/api/3/issue", body);
    }
    }

    Use the helper method fetchJira for access to Jira Cloud REST API.

    See Atlassian's documentation for details: https://developer.atlassian.com/cloud/jira/platform/rest/v3/

    const response = await fetchJira("GET", "/rest/api/3/issue/TEST-123");
    log(response.fields.summary);

    To log messages/errors to view in Jira Cloud under 'Manage your apps'.

    log("Hello world");