/** This example script console script shows how you can get the versions from one project and copy them to another project on the Script Console.* "All right, title and interest in this code snippet shall remain the exclusive intellectual property of Adaptavist Group Ltd and its affiliates. Customers with a valid ScriptRunner* license shall be granted a non-exclusive, non-transferable, freely revocable right to use this code snippet only within their own instance of Atlassian products. This licensing notice cannot be removed or* amended and must be included in any circumstances where the code snippet is shared by You or a third party." */// NOTE: This script can only copy versions to a project where the versions do not already exist. // Specify the master project to get the versions formdefmasterProjectKey="<ProjectKeyHere>"// Specify the key of the project to copy the version todefprojectToCopyVersionTo="<ProjectKeyHere>"// get the project objectdefproject=get("/rest/api/3/project/${masterProjectKey}").header('Content-Type','application/json').asObject(Map).bodydefversions=project.versions// Loop over each version returned and create a version in the new projectversions.each{// Define some boolean values for storing the archived and released properties for the versionbooleanarchivedValue;booleanreleasedValue// Set the boolean values to the values from the returned versionif(it.archived.toString()=="true"){archivedValue=true;}else{archivedValue=false;}if(it.released.toString()=="true"){releasedValue=true;}else{releasedValue=false;}// Get todays date as a string for any date properties which dont have a value setdeftoday=newDate().format('yyyy-MM-dd').toString()// Declare some variables to store the start and release date valuesdefstartDateValue;defreleaseDateValue// Get the start date and if it is null set it to todays date as a start date is required when creating a version in a new projectif(it.startDate!=null){startDateValue=it.startDate.toString().replaceAll("\\[","").replaceAll("\\]","")}else{startDateValue=today}// Get the release date and if it is null set it to todays date as a release date is required when creating a version in a new projectif(it.releasedDate!=null){releaseDateValue=it.startDate.toString().replaceAll("\\[","").replaceAll("\\]","")}else{releaseDateValue=today}// Make the rest call to create the versionlogger.info("Copying the version with the name of: ${it.name.toString().replaceAll("\\[", "").replaceAll("\\]", "")}")defcreateVersion=post("/rest/api/2/version").header("Content-Type","application/json").body(["description":it.description.toString().replaceAll("\\[","").replaceAll("\\]","")?:"",// Get the desceription and pass an emtpy string if it is null"name":it.name.toString().replaceAll("\\[","").replaceAll("\\]","")?:"",// Get the name and pass an emtpy string if it is null"archived":archivedValue,// Get the archived value and pass an emtpy string if it is null"released":releasedValue,// Get the released value and pass an emtpy string if it is null"startDate":startDateValue,"releaseDate":releaseDateValue,"project":projectToCopyVersionTo]).asString()}return"Versions Copied. Check the 'Logs' tab for more details"
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.