Tags and Status to automatic update from both sides -Jira and DevOps-

Hello,

Im trying to get two things

1 - Jira Status to update the Tag on the DevOps ticket
when Jira status is Dev In Progress then DevOps tag should be Ready for Sprint

2- DevOps Tag to update Jira status
when Tag in Devops is Ready for UAT Testing then Jira Status to change to UAT Testing
And
when Tag in DevOps is Deployed to PRD then Jira status to change to Deployed in Prod

My code is as follows:

Outgoing Jira:

// let DevOps know which JIRA key this came from
replica.key = issue.key

// basic fields
replica.summary = issue.summary
replica.priority = issue.priority
//This line below, transforms description from Markdown to HTML to transfer over
replica.description = nodeHelper.getHtmlField(issue, “description”)
replica.attachments = issue.attachments
replica.status = issue.status

// custom-field mappings (make sure the names match exactly what you use in Azure incoming)
replica.customFields.“DevOpsProject” = issue.customFields.“DevOps Project”
replica.customFields.“CustomerRequestType” = issue.customFields.“Customer Request Type”
replica.customFields.“Estimate” = issue.customFields.“Estimated Effort”


Incoming Jira

if (firstSync) {
issue.projectKey = “ITS”
issue.typeName = “CI”
}

if(!firstSync && syncRequest.remoteSyncEventNumber==1){
issue.customFields.“Remote URL”.value = issueUrl
}

// Map DevOps tags to Jira statuses
// If tag in DevOps is ‘Ready for UAT Testing’ then Jira status should change to ‘UAT Testing’
// If tag in DevOps is ‘Deployed to PRD’ then Jira status should change to ‘Deployed to Prod’
def tagToStatusMap = [
‘Ready for UAT Testing’: ‘UAT Testing’,
‘Deployed to PRD’ : ‘Deployed to Prod’
]

def devopsTags = replica.tags ?:
// Find the first tag that matches our mapping
for (tag in devopsTags) {
if (tagToStatusMap.containsKey(tag)) {
issue.setStatus(tagToStatusMap[tag])
break
}
}


Outgoing DevOps

// Outgoing script (Azure DevOps → Jira)

replica.key = workItem.key
replica.summary = workItem.summary
replica.description = workItem.description
replica.tags = issue.labels


Incoming DevOps

if (firstSync) {
workItem.projectKey = replica.customFields.“DevOpsProject”?.value?.value ?: “DEFAULT_PROJECT”
workItem.typeName = “User Story”
workItem.summary = replica.summary

syncHelper.syncBackAfterProcessing()
}

workItem.description = replica.description
workItem.attachments = replica.attachments
workItem.priority = replica.priority

if (firstSync) {
store()
workItem.customFields.“JIRA”.value = issueUrl
workItem.customFields.“Estimate”.value = replica.Estimate
} else {
workItem.customFields.“JIRA”.value = issueUrl
}

// Add tag ‘Ready for Sprint’ if Jira status is ‘Dev In Progress’.
// Only set the tags field if the status is exactly ‘Dev In Progress’.
if (replica.status?.name == “Dev In Progress”) {
workItem.tags = [“Ready for Sprint”]
}

Any ideas? (This code was suggested by the AI in the Exalate screens)

Thanks

hi @Lautaro

Thank you for connecting with Exalate community and happy to work with you on it.

May I know if you tested that code after getting it by the Exalate AI?

Hello, Ive tried the code in my exalate with my test tickets, Tags dont get created and Status dont get updated, i tried troubleshooting the issue with the exalate AI but even after giving me a few other options, tags and status dont change or get creted. Thank you

Just as extra info, the only part of the code that does not work is the TAG, Status part. the rest works fine

Appreciate the update. I have to check and then test it, once I have the information, will be sharing it with you.

Hi @Lautaro

Thank you for your patience. Please try the following snippet (which I still need to try) and see the outcome:

Jira Outgoing:

// Add tag ‘Ready for Sprint’ if Jira status is ‘Dev In Progress’.
// Only set the tags field if the status is exactly ‘Dev In Progress’.
if (replica.status?.name == “Dev In Progress”) {
// Ensure the existing tags are preserved, and append ‘Ready for Sprint’ if Jira status is ‘Dev In Progress’.
workItem.tags = (workItem.tags ?: ) + [“Ready for Sprint”]
}

This code checks if the Jira status is "Dev In Progress". If it is, it adds the tag "Ready for Sprint" to the list of existing tags in Azure DevOps without removing any existing tags.

Incoming Jira

// Map DevOps tags to Jira statuses
// If tag in DevOps is ‘Ready for UAT Testing’ then Jira status should change to ‘UAT Testing’
// If tag in DevOps is ‘Deployed to PRD’ then Jira status should change to ‘Deployed to Prod’
def tagToStatusMap = [
‘Ready for UAT Testing’: ‘UAT Testing’,
‘Deployed to PRD’ : ‘Deployed to Prod’
]

def devopsTags = replica.tags ?:

// Find the first tag that matches our mapping
for (tag in devopsTags) {
if (tagToStatusMap.containsKey(tag)) {
def mappedStatus = tagToStatusMap[tag]

    // Transition Jira status to the mapped value
    // Assuming the 'mappedStatus' corresponds to a valid Jira status name
    issue.transition(mappedStatus)
    break
}

}

This code maps tags from Azure DevOps (e.g., "Ready for UAT Testing", "Deployed to PRD") to corresponding Jira statuses (e.g., "UAT Testing", "Deployed to Prod"). When a matching tag is found, the Jira status is updated using issue.transition(mappedStatus).

Outgoing Azure DevOps:

// Check Jira status and add appropriate tags to DevOps work items
if (replica.status?.name == “Dev In Progress”) {
// Ensure the existing tags are preserved, and append ‘Ready for Sprint’ if Jira status is ‘Dev In Progress’
workItem.tags = (workItem.tags ?: ) + [“Ready for Sprint”]
}

This is similar to the outgoing Jira sync, but here we are updating the tags in Azure DevOps based on the Jira status.

Incoming Azure DevOps:

// Map DevOps tags to Jira statuses
// If tag in DevOps is ‘Ready for UAT Testing’ then Jira status should change to ‘UAT Testing’
// If tag in DevOps is ‘Deployed to PRD’ then Jira status should change to ‘Deployed to Prod’
def tagToStatusMap = [
‘Ready for UAT Testing’: ‘UAT Testing’,
‘Deployed to PRD’ : ‘Deployed to Prod’
]

def devopsTags = replica.tags ?:

// Find the first tag that matches our mapping
for (tag in devopsTags) {
if (tagToStatusMap.containsKey(tag)) {
def mappedStatus = tagToStatusMap[tag]

    // Transition Jira status to the mapped value
    // Assuming the 'mappedStatus' corresponds to a valid Jira status name
    issue.transition(mappedStatus)
    break
}

}

This code checks tags from Azure DevOps (such as "Ready for UAT Testing" and "Deployed to PRD") and maps them to Jira statuses (like "UAT Testing" and "Deployed to Prod"). If a matching tag is found, it uses issue.transition(mappedStatus) to transition the Jira issue status.

Please check and let me know the outcome.