How to create a simple script in BPS for Jira

Visitas: 16

In this tutorial, we will look at adding a simple script that allows you to execute code.

The code is written in Groovy which is a scripting language based on Java. Which allows you the flexibility to do pretty much anything you need to do. The great thing with this is that it allows you to execute code inside Jira so you can then integrate that code into your processes.

First, let's right-click on scripts and choose ‘New Script’.

Click on your new script to open it in the Code Editor window.

As you type in the Code Editor you will see that the editor does real-time code checking.

If you hover over the error, it will elaborate on the errors found.

In this example, we are going to use a REST API service that returns a JSON object with the time.

You will see online 5 the editor is highlighting a static type checking error. That is because the system is not able to find if the property "CurrentDateTime" belongs to the object. Depending on what the class on line 3 finds in the JSON, will depend on whether it finds the property or not.  So the error is a warning for us here because if the property is not found at runtime, then the script will fail. However, it is fine for this example because it is working code and is normal to write it that way.

At the bottom of the window, you can see 4 tools that give information about the script.

The first tab is Compilation, gives information on the errors that our code has.

The second tab is Output that is useful as it shows the output of the script when we run the script.

The third tab is Execution that shows all of the execution instances of every time we run this script.

The fourth tab is if we are logging information to the system logger.

To see the output of the script, click the Output tab. You will see a blank window.

To run the script, click the ‘Run Script’ button at the top of the screen.

ç

In the Output window at the bottom of the screen, you will see that the script has returned the time.

This is a very basic example where we are calling an external API. But the possibilities of this tool are very useful as you can connect to external tools or databases, or anything that will help your processes.

Thank you for following this tutorial, we hope you find this function very useful in your projects.

CAPTCHA
Esta pregunta es para comprobar si usted es un visitante humano y prevenir envíos de spam automatizado.