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
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.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
def projectManager = ComponentAccessor.getProjectManager()
def projectSource = projectManager.getProjectObjByKey("SOURCE_PROJECT_KEY") // change project name here
def projectDestination = projectManager.getProjectObjByKey("DESTINATION_PROJECT_KEY") // change project name here
def 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Alexey Matveev,
Good job. I have enhanced it a little, not to loose any metadata of versions
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
def projectManager = ComponentAccessor.getProjectManager()
def projectSource = projectManager.getProjectObjByKey("SOURCE_PROJECT_KEY") // change project name here
def projectDestination = projectManager.getProjectObjByKey("DESTINATION_PROJECT_KEY") // change project name here
def 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Verhás István. I modified in this way:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
def projectManager = ComponentAccessor.getProjectManager()
def projectSource = projectManager.getProjectObjByKey("KEY") // change project name here
def projectDestination1 = projectManager.getProjectObjByKey("KEY1") // change project name here
def projectDestination2 = projectManager.getProjectObjByKey("KEY2") // change project name here
def projectDestination3 = projectManager.getProjectObjByKey("KEY3") // change project name here
def versionManager = ComponentAccessor.getVersionManager()
List<Project> projectList = new ArrayList<>();
projectList.add(projectSource)
Collection<Version> versionList = versionManager.getAllVersionsForProjects(projectList, false)
for (version in versionList) {
def versionname = version.getName()
if (versionname.length() >= 3 && versionname.substring(0, 3).equalsIgnoreCase("abc")) {
log.debug("Now adding version " + version + " to " + projectDestination1.name)
versionManager.createVersion(version.name, version.startDate, version.releaseDate, version.description, projectDestination1.id,null, version.released)
} else if (versionname.length() >= 10 && versionname.substring(0, 10).equalsIgnoreCase("def")) {
log.debug("Now adding version " + version + " to " + projectDestination2.name)
versionManager.createVersion(version.name, version.startDate, version.releaseDate, version.description, projectDestination2.id,null, version.released)
} else if (versionname.length() >= 7 && versionname.substring(0, 7).equalsIgnoreCase("ghi")) {
log.debug("Now adding version " + version + " to " + projectDestination3.name)
versionManager.createVersion(version.name, version.startDate, version.releaseDate, version.description, projectDestination3.id,null, version.released)
} else {
//do nothing
}
}
My question is, how I need to load it as a custom listener?
Steps I followed to create the file:
1. Select ""Custom listener"
2. ProjectKey: Selected both source and destination projects
3. Events: I'm not sure what to select, I selected generic one "projectupdatedEvent"
4. Used the above inline code.
Though there are no errors in the code it wasn't copying the version names.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sarath,
The modification seems to be perfect. Actually, this script is intended to be used in script runner terminal window, not as a listener. This script is able to synchronize the existing versions, while the listener approach targets the versions to be created in the future.
As it is mentioned above please visit the documentation of the Version Listener at https://scriptrunner.adaptavist.com/latest/jira/listeners.html#_version_synchroniser_listener .
Regards,
Istvan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Script runner has built in script for it (in Script listener section)
Version synchroniser
Synchronises versions across multiple projects
Out of the box it's not supported in JIRA
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.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You can get all Versions for specific project and then create versions for desired projects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Tarun Sapra for your great help ! I am going to use the script listener "Version synchroniser"
Thank you also @Alexey Matveev and @Stefaan Quackels for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join the largest European gathering of the Atlassian Community and reimagine what’s possible when great teams and transformative technology come together. Plus, grab your Super Fan ticket now and save over €1,000 on your pass before prices rise on 3 June.
Register nowOnline 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.