Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This script should be run with TFS4JIRA Self 9.7 or higher.

...

Tested with: Azure DevOps Services, Jira Cloud, and Jira DC 9.X

This Python script updates the linked AzureDevOps work item ID in each Jira issue. This field is needed in order to properly synchronize Jira issues with ADO work items.

USE CASE

The organization migrated ADO work items from one instance to a different one, resulting in all migrated work items receiving new IDs. The outcome, Jira issues pointed to old work item IDs.

PREREQUISITES:

  1. TFS4JIRA Self-Hosted 9.7 or higher

  2. The latest version of Python: https://www.python.org/downloads/

  3. Python IDE: PyCharm: https://www.jetbrains.com/pycharm/download/ (we will run the script in this editor)

  4. The script:

View file
namechangepasswordamend_wi_id_in_jira_issue.py

INITIAL SETUP IN SCRIPT :

  1. Set the API endpoint URL

    Script
    1. ADO credentialstfs4jira

      1. org_url =

      "TFS4JIRA URL" This is your TFS4JIRA synchroniser URL
    2. jira_user = "" Email or login for synchronization user

    3. jira_password = "" Password or Personal Access Token in case of cloud instance

    4. tfs_user = "" Email or login for synchronization user

    5. tfs_password = "" Password or Personal Access Token in case of cloud instance

  2. Set the Bearer Token

    1. bearer_token = "" In order to obtain this token, please start TFS4JIRA and click “manage profiles with API” link just below the blue ‘create profile’ button. This link will take you to Swagger. Click ‘APIToken Page’ link to display the token

      Image Removed

WHAT WILL IT DO?

      1. '<https://dev.azure.com/<ORG>/'> - Azure DevOps (ADO) organization URL

      2. pat = 'xemhf6ez4i7svvho' - Personal access token (replace with your own token)

      3. project = 'xyz1234' - Project name in Azure DevOps (ADO)

      4. JiraFieldInADO = 'Custom.T4J_IssueKey' - A custom field in ADO used to store JIRA Issue Key

    1. JIRA credentials

      1. JiraUrl = 'http://52.24.97.338:8080' - Set JIRA URL

      2. auth = ('<username>', '<password>') - Set the authentication credentials - username and password

      3. ADOfieldInJira = 'customfield_10112' - A custom field in Jira used to store work Item ID

  1. OPTIONAL - the query used to fetch ADO work items can be modified to only fetch relevant work items (for example, with specific Area Path)

    Code Block
    languagesql
    wiql_query = f'SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = "{project}" and [{JiraFieldInADO}] <>""'


WHAT WILL IT DO?

  1. The script will get the list of all the profiles work item IDs and saved Jira keys from the TFS4JIRA new ADO instance.

  2. Having the list of guidsIDs, the script will for each guid, run API updating synchronisation user credentials (provided at the beginning of the script)Script connect to each Jira issue (using the obtained key) and update ADOfieldInJira with a new work item ID.

  3. The script will display error messages at any step in the PyCharm console, informing what went wrong

  4. The script will also save a log file with the following format (each run, one log file):
    workitem_update_script_log_<date>-<time>

    Image Added

    1. The log file is saved in the same location as the script file and is immediately visible in PyCharm’s project files explorer