We decided to move a project from our Data Center Jira instance to cloud in a Jira Service Management instance and we would like to set the mentions in confluence also to the cloud instance project, so we would need a way to update all the Jira Issue/Filter macros to point to cloud instead of the Data Center project. The problem is that other projects which are mentioned in confluence are not migrated to cloud, so those ones should not be updated. The only solution I found is Script Runner update macro built-in script, but without a console script it would update all the macros it finds. It is not exactly clear how to check what the parameters are in the macro.
Here is my code so far(obviously it doesn't work):
import com.atlassian.confluence.xhtml.api.MacroDefinition
macroTransform = { MacroDefinition macro ->
String url = macro.getParameter('confluence.extra.jira.jira.param.serverUrl.label')
String keyLabel = macro.getParameter('confluence.extra.jira.jira.param.key.label')
String newURL = 'MYCOMPANYCLOUDURL'
if (keyLabel.contains('XYZ-')) {
macro.setParameter('confluence.extra.jira.jira.param.serverUrl.label', url.replace('MYCOMPANYDCURL', newURL))
}
macro
}
For clarity I make another comment so anyone having the same problem can find the solution easily. With the help of @Sahir Maharaj and this post: Update Macro I was able to make a solution for the problem.
import com.atlassian.confluence.xhtml.api.MacroDefinition
macroTransform = { MacroDefinition macro ->
def url = macro.parameters.key
if (url.startsWith('XYZ-')) {
setMacroParameter(macro, 'serverId', 'ServerIdOfTheConnectedJiraInstance')
}
macro
}
So really there were two problems, first: the way I wanted to access and set the parameters, and second: I wanted to change the server URL instead of the server ID.
I hope this will help someone.
Hello @Illés Ákos
Using ScriptRunner’s macro transformation is a good approach, but the code snippet provided requires some adjustments to ensure it processes only the relevant macros and updates the URLs correctly.
Can you please try this updated script:
import com.atlassian.confluence.xhtml.api.MacroDefinition macroTransform = { MacroDefinition macro -> macro.getParameters().each { key, value -> log.info("Parameter Key: ${key}, Value: ${value}") } String url = macro.getParameter('serverUrl') String issueKey = macro.getParameter('key' String newURL = 'MYCOMPANYCLOUDURL' if (url && issueKey && issueKey.startsWith('XYZ-')) { // Update the server URL if it matches the Data Center URL macro.setParameter('serverUrl', url.replace('MYCOMPANYDCURL', newURL)) } return macro }
After running the updated script, I would recommend to test thoroughly on a small subset of pages to verify the changes.
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your response talks about Bitbucket, while the author's question is about Confluence. Perhaps you added your response to the wrong Question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Trudy Claspill :)
I indeed added the response to the wrong question - Just corrected it.
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sahir Maharaj thank you for your response! It appears that the problem was with the way I tried to access the parameters, although the solution provided did not work for me as is, I was able to leverage some parts of it in the working solution. Thank you again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.