Testing Jira Expressions for SIL Validators

Problem

Use this guide to explore Jira Expressions not covered in the basic SIL Validator templates. 

Solution

Use Atlassian's REST "expression eval" endpoint to test Atlassian expressions. In this example, an issue's custom field will be tested if it equals "testChar". The results can then be used to create a SIL Validator in Jira Cloud. For more information on Jira Expressions, see this Atlassian documentation:

Jira Expressions

For Jira expression types:

Jira Expressions Type Reference

Basic REST Script

Create a basic SIL REST script. For a primer on using httpPost(), see this documentation: httpPost(). This script will read data from "expressions.json" and then post that data as an expression to be evaluated by the specified Jira Cloud instance. Once the SIL script is working, the only thing you will need to change is the "expressions.json" data.

evaluateExpressions.sil

string expressionData = readFromTextFile("expressions.json");   // runnerLog(expressionData);   HttpRequest request; request.headers += httpCreateHeader("Content-Type", "application/json"); // create API KEY here: https://id.atlassian.com/manage/api-tokens request.headers += httpBasicAuthHeader("first.last@example.com", APIKEY);   // string structValues = httpPost("https://<BASE_URL>/rest/api/2/expression/analyse", request, rawData); string structValues = httpPost("https://<BASE_URL/rest/api/2/expression/eval", request, expressionData);   runnerLog(structValues);   number statusCode = httpGetStatusCode(); if (statusCode >= 200 && statusCode < 300) {     runnerLog("SUCCESS"); } else {     string msg = trim(statusCode) + ":" + httpGetErrorMessage() + ":" + httpGetReasonPhrase();     runnerLog(msg); }

Basic true == false Test

Your JSON test can be as simple as "true == false". This will obviously return "false".

expressions.json

{   "expression": "{ expressionTest: true == false }" }

This is the JSON that is returned by Jira:

{"value":{"expressionTest":false}}

Evaluating an Expression Against a Custom Field Value

The following JSON tests whether issue.customfield_10096 equals "testChar". Follow these steps to test:

  1. Change "customfield_10096" to they id of the custom field you wish to evaluate. 

  2. Update "DEMO-1" to an issue key you wish to evaluate.

  3. Manually update the target custom field to "testChar" in the Jira UI

expressions.json

This evaluates true:

Using the "expressionTest" as a Jira Expression in a SIL Validator

Once you have configured a SIL Validator, paste the value of "expressionTest" in the "JIRA expression" box in the final step of the "Add Parameters to Validator" wizard.

Running the Expression Tester from the SIL Runner Gadget

  1. Start by configuring the SIL Runner Gadget. Add an execution script and a parameters script.

  2. Reconfigure the JSON and execution script so that it accepts a key and expression test value.

     

  3. Add a struct so SIL can accept the returning JSON data.

     

  4. Add a template script for input.

Final SIL Runner Script

The final executable script looks like the following. Note how gadget_getSingleValue() gets user input.

Related articles

Filter by label

There are no items with the selected labels at this time.