Jira Automation with Jira Edge Connector: A Guide to Script Arguments

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Summary

The Jira Automation and Jira Edge Connector (JEC) functionalities can help users automate operations on their on-premises systems. This feature allows users to send JSON messages to the on-prem system with key-value pairs, which can help them perform customized actions based on specific events or conditions. However, some users have found it difficult to understand, especially on the structure and content of arguments used in these scripts. This article aims to provide users with clearer instructions on how to effectively use argument content.

Solution

Understanding the Script Execution Environment

When an automation action triggers a script via JEC, the system passes several arguments to the script, which can be utilized within the script for various operations. The arguments include:

  1. A JSON payload containing data and key-value pairs specified in the automation setup.

  2. An API key in plaintext (use with caution due to security considerations).

  3. The log level.

  4. The API URL.

The position of these arguments can vary based on how the automation is configured. Users must adapt their scripts to correctly identify and use these arguments.

Adapting Scripts Across Different Scripting Languages

Scripts need to be tailored to correctly identify the position of each argument. Below are guidelines for handling arguments in various scripting languages, emphasizing the need for adaptability.

Groovy (.groovy)

// Adjust the index based on the argument's position
def payload = new JsonSlurper().parseText(args[index])

Python (.py)

import sys
import json
# Adjust the index based on the argument's position
payload = json.loads(sys.argv[index])

Go (.go)

import (
	"encoding/json"
	"os"
)
func main() {
    // Adjust the index based on the argument's position
	var payload map[string]interface{}
	json.Unmarshal([]byte(os.Args[index]), &payload)
}

PowerShell (.ps1)

# Adjust the index based on the argument's position
$payload = $args[index] | ConvertFrom-Json

Shell Scripts (.sh)

# Adjust the index based on the argument's position
payload=$(echo $index | jq '.')

Batch Files (.cmd and .bat)

@echo off
REM Adjust the index based on the argument's position
set payload=%index%

Handling Automation Script Arguments in Python for Jira Service Management

For a detailed example of how to work with the Jira Edge Connector and handle script arguments in Python, please refer to this example script provided by Atlassian on GitHub.

Best Practices and Pitfalls

  • Security: Handle the plaintext API key argument with care to avoid security risks.

  • Validation: Jira doesn't validate your key-value pairs; ensure you verify them within your script.

  • Language Specifics: Familiarize yourself with how each scripting language handles arguments to efficiently extract and utilize the passed data.

This article aims to help you understand how to use the automation feature of Jira Service Management with JEC. It's important to know that Atlassian Support can verify if JEC correctly receives information, but we don't provide support for scripting issues. If you need help with scripting or specific use cases, we recommend engaging with the Atlassian Community. There, you can collaborate with other users and experts to share knowledge and solutions. Developing your scripting skills independently will also help you create tailored solutions that meet your specific needs.

Last modified on May 13, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.