Working out how to find the absolute path of a file run by ScriptRunner is a handy skill - it means not having to statically define the file root. So how does one identify an executed script’s absolute file path?
At GLiNTECH, we like to structure ScriptRunner projects for Atlassian products like regular development projects - that is, being able to have non-production and production versions of scripts. It would be great to always develop on a non-production instance, but even for SIT, we commonly see scripts deployed on the production server.
To use the default mechanism, user libraries must be located in relation to the script root, ie. <Jira home>/scripts:
That doesn't help to separate production from non-production scripts, and new script roots can only be defined as a JVM option on start of Jira. Instead, scripts must be imported from files at runtime:
The pattern here is to deploy a repository and run scripts there that load libraries in other locations in that repository. You could walk the repository to find files and import as libraries. You lose ScriptRunner's static type checking but that's a small price to pay for safe rapid development.