YouTrack InCloud 2017.4 Help

Import from Trac

Follow the instructions on this page to import tickets from Trac using a dedicated module from the YouTrack Python Client Library. This procedure requires the following steps:

  1. Set up your local environment.
  2. Customize the mapping between the fields in your Trac database and the issue attributes in YouTrack.
  3. Import your issues.

Import Details

If the Trac database contains references to entities that do not already exist in YouTrack, they are created. The user account that you use to run the import should have permission to create projects, issues, users, and possibly more. We recommend that you use an account with a System Admin role to execute the import script.

New entities are created as follows:

EntityDescription
ProjectsThe Python script lets you import all issues from a source project at once. If the project does not already exist, a new project is created.
  • The project name and ID are assigned based on the values from the Trac database.
  • The user who executes the import script is set as the project lead.
UsersSeveral issue attributes like reporterName and Assignee store references to user accounts. For each account that does not match the login or email for an existing user in YouTrack, a new user account is created. There are two types of users in Trac:
  • Registered users with a login and a password. These users are imported to YouTrack with their original name and email.
  • Unregistered users who specified a name and an email address or a name only when creating or adding a comment the ticket. These users are imported only when an email address is provided. Users without email addresses are imported as guest.

    There is an option in the mapping file that lets you import all unregistered users as guest instead of creating new accounts in YouTrack.
All new user accounts are assigned randomly-generated passwords. To log in to YouTrack, imported users must click the Reset password link on the login page and create a new password.


References to users in the imported data are mapped to existing accounts in YouTrack. If a match is not found, a new user account is created.

Imported users are allocated a license according to your subscription plan. For users that exceed your per-user license limit, the imported users are flagged as banned.

For more information, see Ban User Accounts.

Custom FieldsIf the import data contains a field that does not exist in YouTrack, the custom field is created and added to the target project.
  • The field name and type are set according to the definitions in your mapping file.
  • The properties for the custom field are set as follows: autoAttached=true, isPrivate=false, defaultVisibility=false.
Field ValuesIf the source file contains new values for an existing field, they are added to the current set of values.
TagsKeywords in Track are imported as tags.
Work ItemsTrac offers plugins that support time tracking. The import script automatically detects and imports time tracking values from supported plugins. These values are added to imported issues as work items.

Set Up Your Environment

Import to YouTrack is supported by the YouTrack Python Client Library. This library is basically a wrapper for the YouTrack REST API. You won't actually need to do any programming in Python, but you do need to install Python and download the client library.

To set up your environment:

  1. Download and install Python. The Python Client Library is compatible with Python 2.7+. Python 3 releases are not supported. You can choose whichever installation directory you prefer.

    The latest versions of macOS, CentOS, Red Hat Enterprise Linux (RHEL), and Ubuntu come with Python 2.7 out of the box. If you're working with any of these operating systems, continue with the next step.
  2. Download the latest version of the YouTrack Python Client Library from GitHub.
  3. Extract the contents of the ZIP archive to a folder in your local directory. You can extract the files to whichever folder you prefer.

Customize the Mapping Definitions

The next step is to map the fields in your Trac database to attributes in YouTrack. The client library contains a sample file that you can customize to match your import data. The file is saved as defaultTrac.py in the python/tracLib subfolder of the client library. This file contains mappings for all of the fields that are required for successful import and definitions for most custom field types.

To use the default mapping definitions, skip this procedure and import your data.

To customize the mapping definitions:

  1. Either open the defaultTrac.py file or open a new file in a text editor and paste the content of the default mapping file.
  2. Verify that all of the data in your Trac database is mapped to the desired values in YouTrack. For a description of the default mappings, see Default Mapping.
  3. Set values for the parameters that manage user import:
    • tracLib.DEFAULT_EMAIL — Assigns a default email address to users who are imported without an email.
    • tracLib.ACCEPT_NON_AUTHORISED_USERS — If True, unregistered users are imported to YouTrack. If False, unregistered users are imported as guest.
  4. If used, specify the time tracking plugin that is enabled in Trac. The default parameter in the mapping file is set to tracLib.SUPPORT_TIME_TRACKING = "auto", which detects and imports time tracking values from supported plugins automatically. You can also specify the plugin from which data is imported:
    ValueDescription
    trachoursImports data from the TracHoursPlugin.
    timingandestimationpluginImports data from the TimingAndEstimationPlugin.
  5. If you created a new file, perform the following steps:
    • Save your mapping file with the extension .py and add it to the <unzipped library directory>/python/tracLib directory.
    • Open the trac2youtrack.py file in the python/tracLib subfolder of the client library.
    • Locate the reference to the defaultTrac module and set the value to the name of your mapping file (without the .py extension). Use the following example as a guide:
      from string import capitalize import urllib from youtrack.connection import Connection from tracLib.client import Client import youtrack import sys import tracLib import tracLib.<mapping file name> import youtrack.connection from youtrack.importHelper import *
    • Save and close the trac2youtrack.py file.
    If you modified the defaultTrac.py file instead, save and close the file.

Import Your Data

The last step is to run the command that imports your data from Trac.

To import your data:

  1. Open the command-line interface that is supported by your operating system.
  2. If necessary, change the current directory to the installation directory for Python. For example (Windows):
    cd C:\Python27
  3. Enter the following command:
    python trac2youtrack.py target_url target_login target_password project_ID project_name path_to_trac_environment
    Replace the command-line parameters with values as described here:
    ParameterDescription
    target_urlThe base URL of the target YouTrack server. For YouTrack InCloud instances, your base URL includes the trailing /youtrack. For example: https://company.myjetbrains.com/youtrack
    target_loginThe login for a YouTrack administrator account.
    target_passwordThe password for the YouTrack administrator account.
    project_IDThe ID of the target project in YouTrack.
    project_nameThe name of the target project in YouTrack.
    path_to_trac_environmentThe path to the source project in Trac.
    • The command executes the Python import script.
    • If successful, the following line is printed in the command-line interface for each issue:
      Issue [ <issue ID> ] imported successfully
  4. Check the project that you imported issues into and verify that the data is presented properly. If you are not satisfied with the results and want to re-import the data:
    • Delete all of the issues that were created during import. If you imported issues into a new project, simply delete the project.
    • Edit your mapping file.
    • Run the import script again.

Default Mapping

The Python Client Library includes a default mapping file for importing issues from Trac to YouTrack. The file is saved as defaultTrac.py in the python/tracLib subfolder of the client library.

The import script trac2youtrack.py contains a reference to the default mapping file. If you create a custom mapping file with a different name, update the reference to the mapping file in the script as described in the above procedure.

Ticket Type

Tickets in Trac use the default types defect, enhancement, and task. The default mapping file contains a TYPES dictionary that maps these values to corresponding values for the Type field in YouTrack.

TYPES = { "defect" : "Bug", "enhancement" : "Feature", "task" : "Task", }

Pay attention to the following guidelines when you edit this section of the mapping file:

  • The left side of the mapping references the value for the Type field in Trac. If you have added custom values to this field, add a new definition for each value to the dictionary.
  • The right side of the mapping references the corresponding values for the Type field in YouTrack. If you specify a value for the Type field that does not already exist, it is added to the field during import.

Ticket Priority

Similar to the mapping for the Type field, this dictionary maps values for the Priority field in Trac to the field with the same name in YouTrack. Follow the same guidelines as for issue type to customize this section of the mapping file. The mapping for default issue priority is as follows:

PRIORITIES = { "trivial" : "Minor", #Minor "minor" : "Normal", #Normal "major" : "Major", #Major "critical" : "Critical", #Critical "blocker" : "Show-stopper" #Show-stopper }

Ticket Resolution and Status

Values for both the Resolution and Status field in Trac are mapped to values for the State field in YouTrack. The default mapping for these values is as follows:

RESOLUTIONS = { "duplicate" : "Duplicate", "fixed" : "Fixed", "wontfix" : "Won't fix", "worksforme" : "Can't Reproduce", "invalid" : "Can't Reproduce" # : "To be discussed } STATES = { "accepted" : "Submitted", "new" : "Open", "reopened" : "Reopened", "assigned" : "Submitted", "closed" : None }

Ticket Fields

The tracLib.FIELD_NAMES dictionary maps field names in Trac to custom fields in YouTrack. You can update the mappings in this section to import data to specific custom fields. The default mapping file only contains definitions for fields that do not match existing fields in YouTrack:

tracLib.FIELD_NAMES = { "Resolution" : "State", "Status" : "State", "Owner" : "Assignee", "Version" : "Fix versions", "Component" : "Subsystem", "Test_five" : "YT Select" }

Pay attention to the following guidelines when you edit the custom field mapping:

  • The left side of the mapping references the field name in Track.
  • The right side of the mapping references the name of the custom field in YouTrack.
  • If you do not specify a mapping for a field in Trac that does not match a target field in YouTrack, a custom field is created with the same name as in Trac.

    For example, older versions of Trac include a field for Severity. The default mapping file defines the field type but does not map the field to a target field in YouTrack. The field and its values are imported as a new Severity field.

Custom Field Types

The tracLib.FIELD_TYPES dictionary maps data types in Trac to custom field types in YouTrack. If you have added fields to the mapping for custom fields, add a corresponding entry to this dictionary to define how the data is stored in YouTrack. The default mapping file contains definitions for the following field types:

tracLib.FIELD_TYPES = { "Priority" : "enum[1]", "Type" : "enum[1]", "State" : "state[1]", "Fix versions" : "version[*]", "Affected versions" : "version[*]", "Assignee" : "user[1]", "Severity" : "enum[1]", "YT Select" : "enum[*]", "Subsystem" : "ownedField[1]" }

Pay attention to the following guidelines when you edit the field type mapping:

  • The left side of the mapping references the name of the custom field in YouTrack. These values must exactly match the custom field name in the FIELD_NAMES dictionary.
  • The right side of the mapping references the field type in YouTrack. For a list of valid types, refer to the Administration REST API.
  • If the target field already exists in YouTrack, you do not need to include it here.
  • You cannot change the data type of an existing field. For example, if the existing Assignee field stores single values (user[1]), you cannot use user[*] in the mapping file and import multiple assignees. You must first update this property for the Assignee field in the YouTrack user interface, then import the data.
Last modified: 4 January 2018