Originally asked by Syed Majid Hassan on 24 September 2022 (original question)
Azure DevOps (ADO) - Jira Cloud syncronization requirements:
______________________________________________________
1. The basic syncronization between standard fields should be working i.e. comments, attachments, etc.
2. If a sprint gets created in ADO, it should be automatically created on Jira side with the same information.
3. The issue (on Jira side) should always be assigned to the correct sprint as per iteration path value from ADO.
4. A custom field called “Team” (ADO side) should sync to a custom select field called “ADO Team” (Jira side).
5. If any new values are added to the custom field on ADO side, these should be dynamically created on Jira side.
I have just completed the use case of syncing a sprint to Jira dynamically i.e. if a new sprint is created and assigned to a workItem, it should be created on Jira side with the same information. The following code snippets achieve this:
Azure Devops Outgoing Script Expand source
def res = httpClient.get("/Majids%20Development/Majids%20Development%20Team/_apis/work/teamsettings/iterations",true)
debug.error("${res}")
def flag = 0
int i = 0
for (;i<res.value.size(); i++){
if (res.value[i].path == replica.iterationPath){
flag =1
break
}
}
if (flag == 1){
replica.customKeys."sprint_name" = res.value[i].name
replica.customKeys."sprint_start" = res.value[i].attributes.startDate
replica.customKeys."sprint_end" = res.value[i].attributes.finishDate
}
replica.customFields."Team" = workItem.customFields."Team"
Jira Cloud Incoming Script Expand source
if (replica.customFields."Team".value)
issue.customFields."ADO Team".value = nodeHelper.getOption(issue, "ADO Team", replica.customFields."Team".value, true)
def list = httpClient.get("/rest/agile/1.0/board/3/sprint")
int flag = 0
for (int i=0; i<list.values.size(); i++){
if (list.values[i].name == replica.customKeys.'sprint_name')
flag = 1
}
String startDate, endDate;
if (flag == 0){
// debug.error(replica.customKeys."sprint_name")
if (replica.customKeys."sprint_start"){
startDate = replica.customKeys."sprint_start".trim()
startDate = startDate.replaceAll("Z",".000+05:00").trim();
}
if (replica.customKeys."sprint_end"){
endDate = replica.customKeys."sprint_end".trim()
endDate = endDate.replaceAll("Z",".000+05:00").trim();
}
def res = httpClient.post("/rest/agile/1.0/sprint", "{\"name\": \"${replica.customKeys.'sprint_name'}\", \"startDate\": \"${startDate}\", \"endDate\": \"${endDate}\", \"originBoardId\": 3}")
}
def res = httpClient.get("/rest/agile/1.0/board/3/sprint")
for (int i=0; i<res.values.size(); i++){
if (res.values[i].name == replica.customKeys.'sprint_name')
issue.customFields.Sprint.value = res.values[i].id
}
The attached video(old community) shows the script in action.