Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The usage outside the issue context is very similar. However, due to the nature of the persistent keyword, the variable, in this case, becomes a global variable. Take for instance the following script, run from the SIL™ Runner gadget:

Code Block
languagejava
persistent number counter = 1; 
persistent boolean flag = false; 
 
TEST-1.description += "\n" + counter + "(" + flag + ")"; 
 
flag = !flag; 
 
counter ++;


The counter variable will be incremented as before (starting from 1) and the text above will be re-appended to the issue 'TEST-1'. However, if we change just the issue, say to 'TEST-2', the counter will retain its previous value, incrementing from the value it stopped when you run the above for the TEST-1 issue. Just try it!

Info

Persistent variables are effectively global if used outside of the issue context.

Example Use Cases

Stored Passwords

It is not a good practice to have passwords stored in your script. One way to achieve this is to store the password in a persistent variable. To create the password as global variable run the following script once through the SIL Runner Gadget or the SIL Scheduler:

Code Block
languagejava
persistent string apiPassword = "password132";

Then, in a script where the password is required, you can retrieve the value using the getPersistentVar() routine.

Code Block
languagejava
HttpRequest request;
HttpHeader authHeader = httpBasicAuthHeader("admin", getPersistentVar("apiPassword"));
request.headers += authHeader;
...

File Path

If you commonly use routines that require the full file path of a file you can save yourself a step by storing the root file path as a persistent variable. To create the password as global variable run the following script once through the SIL Runner Gadget or the SIL Scheduler:

Code Block
languagejava
persistent string rootPath = "/var/atlassian/application-data/jira/";

Then, in your script, you can retrieve the value.

Code Block
languagejava
string path = getPersistentVar("rootPath") + "silprograms/calls/test.sil";

Contents

Table of Contents

See More

Child pages (Children Display)
pagePSCONF:New Copy - Persistent Variables