Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to mass-edit Post functions on transitions in all Workflows

Alexey Gusev
Contributor
December 7, 2023

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.

2 answers

1 accepted

0 votes
Answer accepted
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 9, 2023

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

Alexey Gusev
Contributor
January 9, 2024

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.

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 7, 2023

Hi @Alexey Gusev

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

Alexey Gusev
Contributor
December 7, 2023

@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.

Suggest an answer

Log in or Sign up to answer