How could I sycnhronize versions between 2 projects please ? Or copy them from one to another ?
ps : I have scriptrunner so if you want to share your script with me I would be grateful to you.
Camille
Script runner has built in script for it (in Script listener section)
Version synchroniserSynchronises versions across multiple projects
Out of the box it's not supported in JIRA
https://jira.atlassian.com/browse/JRASERVER-2698?focusedCommentId=1691393&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-1691393
You can actually also rely on a synchronizer plugin such as Exalate. This plugin would allow to keep synchronized versions (and issues under it) between two different projects.Let me know if you need any additional help figuring this out.
In ScriptRunner your script would look something like this
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.project.Projectimport com.atlassian.jira.project.version.Versiondef projectManager = ComponentAccessor.getProjectManager()def projectSource = projectManager.getProjectObjByKey("SOURCE_PROJECT_KEY") // change project name heredef projectDestination = projectManager.getProjectObjByKey("DESTINATION_PROJECT_KEY") // change project name heredef versionManager = ComponentAccessor.getVersionManager()List<Project> projectList = new ArrayList<>();projectList.add(projectSource)Collection<String> versionList = versionManager.getAllVersionsForProjects(projectList, false).stream().map{it.getName()}.collect()for (version in versionList) { log.debug("Now adding version " + version + " to " + projectDestination.name) versionManager.createVersion(version, new Date(), new Date() + 7, "New version description", projectDestination.id, null)}
You need to add logic how to handle already existing versions.
Documentation here -https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_version_synchroniser_listener
from the docs
"
Please understand the functionality of the listener before implementing it in your production environment. The listener propagates the following:
version creates to all target projects, when a version is created in the source project"
And if you want to use groovy script in the script console to copy the version via a script then it can be easily achieved using VersionManager
https://docs.atlassian.com/DAC/javadoc/jira/7.1.0-m01/reference/com/atlassian/jira/project/version/VersionManager.html
You can get all Versions for specific project and then create versions for desired projects.
Hi @Alexey Matveev,
Good job. I have enhanced it a little, not to loose any metadata of versions
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.project.Projectimport com.atlassian.jira.project.version.Versiondef projectManager = ComponentAccessor.getProjectManager()def projectSource = projectManager.getProjectObjByKey("SOURCE_PROJECT_KEY") // change project name heredef projectDestination = projectManager.getProjectObjByKey("DESTINATION_PROJECT_KEY") // change project name heredef versionManager = ComponentAccessor.getVersionManager()List<Project> projectList = new ArrayList<>();projectList.add(projectSource)Collection<Version> versionList = versionManager.getAllVersionsForProjects(projectList, false)for (version in versionList) { log.debug("Now adding version " + version + " to " + projectDestination.name) versionManager.createVersion(version.name, version.startDate, version.releaseDate, version.description, projectDestination.id,null, version.released)}
The existing version logic is still missing.
how to modify the code where if the version in the source project has word 'abc' then it should be created in project a, if the version in the source has word 'xyz' then it should be created in project b?
Hi @Sarath,
You have to define two destination projects, projectDestinationA and projectDestinationB. In the last line of createVersion you need an 'if' to select the proper project to create the version in.
Be warned that you have only specified only two cases of four ones. Missing the case when both abc and xyz can be found in the source version, and the other missing case when none of them is there.
Regards,
Istvan
Jira CLI has `copyVersion` and `copyVersions` options.https://bobswift.atlassian.net/wiki/spaces/JCLI/pages/6684679/Reference#Reference-copyVersion
copyVersion : Copy a version from one project to the same project or another project.copyVersions : Copy all versions from one project to another project.e.g. jira.sh --action copyVersions --project "zjiracli" --toProject "zjiracliC" --replace
It looks like you're new here. Sign in or register to get started.