Hello!
I have a problem. I actively use ScriptRunner, and I have a huge number of workflows where conditions, validators, and post functions are implemented using the functionality of this plugin.
In these conditions, validators, and post functions, I use my own classes that I created through Script Editor (the location of the class files on the server: <Jira home directory>/scripts).
Recently, I needed to make changes to these classes, which involves changing the packages. For example, the class ISSUE was in the package groovy.classes, but now it needs to be changed to groovy.classes.issue.
After I saved the modified class, I see the following errors when transitioning in the Workflow:
The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script144.groovy: 2: unable to resolve class groovy.classes.ISSUE
@ line 2, column 1.
import groovy.classes.ISSUE
^
1 error
Therefore, my question is, how can I mass-change the packages in similar lines like:
import groovy.classes.ISSUE?
Doing it manually is not feasible at all, as I would have to make about 5,000 manual changes in each Workflow.
You could have avoided this in the first place by limiting the use of in-line scripts.
When you start creating your own classes, it's probably a good idea to start maintaining your code outside of jira. So if a post function or condition etc needs to access custom classes, you can create them as script files as well. Then, common/similar scripts can be re-used across different workflow configurations and updating the common file will take immediate effect in all workflows.
Another advantage of maintaining the code in an external environment is the ability to use modern IDE like Intellij. In this case, when you move a package, the tool will automatically identify all the instances where that package is changed and update the import accordingly in all the relevant files. So even if you have hundreds of small scripts, you can update them easily in intellij then just refresh all the files in your server.
But clearly, it's too late now.
So you are looking to perform bulk search/replace of many in-line scripts.
I don't think there is any sort of built-in way to do that. In theory it might be possible to wrong a console script that will iterate over all the workflows, then all the transitions, then all the conditions, validators, and post functions and identify configurations related to scriptrunner and examine the FIELD_INLINE_SCRIPT argument (after some base64 decoding).
You can see that this would not be very simple. Then you'd need to identify the correct API to use to create a draft of your workflow, modify those configurations and publish the workflow.
The development time, testing time and inherent risk would not be worth it for me. I think my time would be best served taking the time to fix each workflow manually by converting those inline scripts into script files to be protected from that problem in the future.
You can use the Script Registry built-in script to identify all the configurations to fix.
Best of luck
Peter-Dave Sheehan, thank you for your response! I used the second option and, following your logic, wrote a Groovy script that helps me solve this problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your case seems to be a cache-related problem.
Please use ScriptRunner Buil-In Script, i.e., Clear Groovy Class Loader, to clear up your old code cache and retest your code.
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.
@Ram Kumar Aravindakshan _Adaptavist_
Thank you for the response, but that's not what I need.
I'll try to explain it differently:
I have a class:
package groovy.classes
public class ISSUE {
...
}
There is a Post function that is used in the Workflow as an inline script:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import groovy.classes.ISSUE
ISSUE Issue = new ISSUE()
...
But here's the problem, after I change the package of the ISSUE class to
package groovy.classes.issue
public class ISSUE {
...
}
my current import in the Post function will stop working and throw an error, as I mentioned earlier.
And there are many such Post functions, so I'm looking for a way to mass-edit the code of these Post functions.
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.