Jira Issue/Filter macro update with Script Runner, but filter what to update

Illés Ákos
Contributor
January 10, 2025

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

}
Any help or input would be much appreciated!

2 answers

1 accepted

1 vote
Answer accepted
Illés Ákos
Contributor
January 15, 2025

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.

0 votes
Sahir Maharaj
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.
January 11, 2025

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.

Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 11, 2025

@Sahir Maharaj 

Your response talks about Bitbucket, while the author's question is about Confluence. Perhaps you added your response to the wrong Question.

Like Sahir Maharaj likes this
Sahir Maharaj
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.
January 12, 2025

Thanks @Trudy Claspill :)

I indeed added the response to the wrong question - Just corrected it. 

Thanks!

Illés Ákos
Contributor
January 15, 2025

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

Like Sahir Maharaj likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events