I have a couple Groovy scripts that one of my co-workers and I run every week to collect some Jira ticket stats. I recently had to tweak the script some for the Groovy 3.0 update in the ScriptRunner for Jira version 7.0 update. That was fixed and things looked, well, groovy.
Today, our SR4J install was updated to 7.1.0. Now when either script is run from file, I get this error (mod the script name):
If I take the contents of the file and paste it into Script Console under the Inline tab, the whole thing works fine with no warnings.
I'm relatively new to Groovy and my Java knowledge stops around version 1.1, but from what I can tell, if I want to run the stats1.groovy script from file, I need to have some Package declaration at the start of the file.
I tried:
Package var.atlassian.application-data.jira
at the top since the warning said that that's what it was expecting. That lead to the interpreter thinking that I was trying to subtract "data.jira" from "var.atlassian.application" and subsequent errors for "var" and "data" being undeclared, some other errors, and then the warning from above, but this time instead of finding an empty string, it found 'var.atlassian.application'.
Am I at least going down the right path here with using "Package"? I tried putting double and single quotation marks around the package name. I tried escaping the hyphen. Nothing worked. Is there some other way to tell the interpreter that '-' should be taken literally and not treated an an operator? Do I have to rearrange the container's directory structure to eliminate the warning?
Looking at https://groovy-lang.org/syntax.html#_identifiers, I see that in section 3.1 that the identifiers like 'a-d' are invalid, but then in section 3.2 they talk about quoted identifiers, but I'm not sure how (or if) they can be applied to the Package name.
Ideas?
Hi @PeteToscano
Could you please share a screenshot of your Script Editor, i.e. like:-
I am asking for this to understand how your packages are displayed.
Generally, the Groovy code files and packages should be added to the scripts/ folder, but I did not see it in your description.
Thank you and Kind regards,
Ram
Hi Ram,
We're having a similar issue. Our scripts are located in the scripts/ folder. This issue seemed to only appear once we updated from Scriptrunner 6.57-->7.2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please share a screenshot of your Script Edit, as shown in my previous comment?
Also, could you please try to repeat the steps in Safe-Mode, i.e. with all third-party plugins disabled except for ScriptRunner? This is to rule out if there is any issue associated with other third-party plugins.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram,
Our JIRA admin wasn't willing to run in safe-mode. That being said, our issue seemed to "magically" get solved one day. My guess is that there was something misconfigured with the proxy in the new environment we migrated to, which got fixed at some point.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, Adaptavist is now saying "Psych! Never mind."
They're no longer requiring "package" and are going to remove or change the message.
Why is there an Incorrect Package Declaration Message in the Script Editor?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @WW
The warning message will appear if you have given an incorrect package name that doesn't match the packages in which your groovy code is placed.
If your code is placed in the outermost folder, i.e. the scripts/ folder, then no package declaration is required.
However, if it is placed in other inner directories, for example, scripts/mock/, then your code must include the package name mock, for example:
package mock
....
....
....
def customFieldManager = ComponentAccessor.customFieldManager
....
....
....
Previously, this was not enforced in all the components except for the REST Endpoint.
But now, the warning message is included in all the components for best practices.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to Why is there an Incorrect Package Declaration Message in the Script Editor?, there will still be a warning message but the package name will not be required.
If you have more than one script with the same name under different folders/packages, that's where the package name is needed, otherwise, ScriptRunner might point to the wrong one.
That page explicitly says:
there is no requirement to fix existing scripts, unless you want to
If that page is to be believed, you don't have to enter package <name> for every script, but it will warn you that you should. Nothing will be "enforced."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We have added sub-folder structures under scripts such as script_behaviors, script_fields, script_listeners, etc. to organize and simplify.
So it looks like we will need to explicitly declare the sub-folder(s) as the package in each script residing in a sub-folder in preparation for SR 8.
Correct?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the delay, Ram. I had lost track of this thread for a while.
Thank you for pointing out the need to put the Groovy scripts into the scripts folder. I copied the scripts into there and changed the path in the script field under the Console to just the script name. It run without warning, and it actually offered to autocomplete the script name. Not only that, but now the script editor seems to be working. Huzzah!
Thanks,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.