Syncing Timebooking entries bidirectional between Azure Devops and Jira Server

Originally asked by msch on 14 April 2022 (original question)


Hey everyone,

i am currently trying to sync timbooking entries on tickets from Jira Server side ( Tempo ) to Azure DevOps( Time Log ) and vice versa. Has anyone already achieved that in scripting mode?

Thanks for any hints and help.

Best Regards

Mat


Comments:

Serhiy Onyshchenko commented on 22 April 2022

Hello, msch thanks for your question.
I’m afraid I don’t see the Time Log in my azure. Is it coming from an extension?
Regards, Serhiy.

msch commented on 22 April 2022

Hello Serhiy Onyshchenko , yes the time logging feature is coming from an extension. I was testing with http://www.timelogextension.com/.

Regards, Matthias

Answer by Serhiy Onyshchenko on 22 April 2022

Hello, msch ,

unfortunately, this addon is not supported by Exalate out-of the box.

However, what you may do is make Exalate interact with the TimeLog API from the incoming sync script using the

replica.addedWorkLogs.each { remoteWorkLog ->
  def createdTimeLog = httpClient.http(
    "POST", // method      "${TIMELOG_URL}/${ORGANIZATION_ID}/timelog...", // URL
     ["queryParam1":["queryParamValue1"]], // query params
     JsonOutput.toJson(["field":"value"]), //body
     ["Content-Type": ["application/json"], "Authorization": ["BASIC ${"admin:admin".bytes.encodeBase64().toString()}"]]  ) { response ->
    if (response.code >= 300) {
      debug.error("Failed to POST a time log to ${TIMELOG_URL}/${ORGANIZATION_ID}/timelog... : "+ response.body)
    }      def js = new groovy.json.JsonSlurper()      def json = js.parseText(response.body)
      return json  }
}

To avoid these things syncing twice, you may link these timelogs to the remote worklogs

def trace = new com.exalate.basic.domain.BasicNonPersistentTrace(
  com.exalate.api.domain.twintrace.TraceType.WORKLOG, 
  createdTimeLog.id as String, 
  remoteWorkLog.id, 
  com.exalate.api.domain.twintrace.TraceAction.NONE, 
  true // should updates / deletes on the log be synced
)traces.add(trace) // make sure Exalate knows, that this time log was created due to that remote work-log

UPDATE:
this covers the syncing Jira → Azure DevOps
For the way-around, just use the same httpClient trick but then to ask TimeLog API for what are the time logs for this workItem

Please, let me know if you’d like me to elaborate.
Regards, Serhiy.