bugzilla-to-jira
Have you been putting off the migration from Bugzilla to Jira because the built-in importer is missing data that you’re not willing to part with?  This problem has been lingering since 2011 with no sign of Atlassian love.
Fear not, has you covered…let’s get it done!
The problem is a misinterpretation of what fields are important.  What you may have seen is….

  • Bugzilla’s “QA Contact” field is completely ignored with no ability to map to a Jira field.
  • Bugzilla’s “OS” and “Hardware” fields are automatically merged and mapped to the Jira Environment field.  This takes away the functionality of a single choice dropdown field.
  • Bugzilla doesn’t have the concept/distinction of “Affects Version” versus “Fix Version”.  Bugzilla’s “Version” is automatically mapped to “Affects Version” leaving the “Fix Version” unmapped with no ability to change the mapping.

Get the data…

First you need to use the Jira Importer for Bugzilla which uses the API to pull in projects and issues/bugs.  So, navigate to <baseURL>/secure/admin/ExternalImport1.jspa, and choose Bugzilla.  You need to do this as a first step so we have issues to map the rest of the data to.  This will likely take a while depending on the size of your Bugzilla installation.

Create CSV with Missing Field Data

While the import is working, we need to retrieve the data for the aforementioned fields and create a CSV file to use for import. Most of the data is stored in the bugs table, but for QA Contact, you will need to use a join to find the user name.  My example is based on a Bugzilla instance using a MySQL database.  If you have the “File” permission in MySQL, it’s best to create the CSV like so…

Export missing custom fields

SELECT bugs.bug_id,bugs.op_sys,bugs.rep_platform,profiles.login_name,bugs.version
FROM orders INTO OUTFILE 'missing_fields.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

I didn’t have that luxury, so an alternative method is to…

mysql -h ${BUGZILLA_HOST} --user=${BUGZILLA_USER} --password=${BUGZILLA_PASS} ${BUGZILLA_DB} -e "SELECT bugs.bug_id, bugs.op_sys, bugs.rep_platform, profiles.login_name, bugs.version FROM bugs LEFT JOIN profiles ON bugs.qa_contact = profiles.userid;" > missing_fields.csv

And then use a healthy mix of tr, sed, and awk to format as comma delimited…

cat missing_fields.csv | tr '\t' ',' | sed "s%,%\",\"%g" | awk '{printf("\"%s\"\n", $0);}' > missing_fields_comma_delimiters.csv

Map Bug data to Jira Issues

When the initial import is complete, find the custom field ID number for the Bug ID field.

  1. Navigate to <baseURL>/secure/admin/ViewCustomFields.jspa
  2. Find the “External issue ID” field and go to “Configure” in the cogwheel menu.
  3. Notice in the URL that is generated, the field ID is there! (i.e. <baseURL>/secure/admin/ConfigureCustomField!default.jspa?customFieldId=10215)

Use the custom field ID number and the CSV file as input arguments, and then run this script to match up issues to the Bugzilla data.

### Usage Example: sh getIssueIDs.sh 10215 missing_fields_comma_delimters.csv > missing_fields_Jira_keys.csv
export sourceField=$1
export bugzilla_dump_file=$2
export re='^[0-9]+$'
export header="project_type,project_name,project_key,issue_id,os_field,hardware_field,qa_contact,fix_version,summary"
export DBUSER='jirauser'
export DBPASS='jiradbpass'
echo $header
while read i; do
 bug_id=$(echo $i | cut -d ',' -f1 | sed -e 's/^"//' -e 's/"$//')
 op_sys=$(echo $i | cut -d ',' -f2)
 rep_platform=$(echo $i | cut -d ',' -f3)
 login_name=$(echo $i | cut -d ',' -f4)
 fix_version=$(echo $i | cut -d ',' -f5)
 # Ignore the CSV headers by checking the bug_id for numeric
 if [[ $bug_id =~ $re ]]; then
   issueID=$(mysql -u ${DBUSER} -p${DBPASS} -N -B -e "select concat(p.pkey, '-', i.issuenum) from customfieldvalue c join jiraissue i on c.issue = i.id join project p on i.project = p.id where c.customfield=$sourceField AND c.stringvalue=$bug_id" jiradb | cut -f1)
   projectKey=$(echo $issueID | awk -F'-' '{print $1}')
   projectType=$(mysql -u ${DBUSER} -p${DBPASS} -N -B -e "select p.PROJECTTYPE from customfieldvalue c join jiraissue i on c.issue = i.id join project p on i.project = p.id where c.customfield=$sourceField AND c.stringvalue=$bug_id" jiradb | cut -f1)
   projectName=$(mysql -u ${DBUSER} -p${DBPASS} -N -B -e "select p.pname from customfieldvalue c join jiraissue i on c.issue = i.id join project p on i.project = p.id where c.customfield=$sourceField AND c.stringvalue=$bug_id" jiradb | cut -f1)
 fi
# Make sure the bug_id matches an issueID
  if [ ! -z "$issueID" ]; then
    echo "\"$projectType\",\"$projectName\",\"$projectKey\",\"$issueID\",$op_sys,$rep_platform,$login_name,$fix_version,"
  fi
done < $bugzilla_dump_file

Import the missing field data…

Now you have a CSV file with the missing data mapped to Jira issues.

  1. Navigate to <baseURL>/secure/admin/ExternalImport1.jspa, and choose CSV as the product you want to import from.
  2. Map the fields to the correct Jira field and import!  All issues will be updated with the values from the CSV.
  3. The final step will be to make sure the new fields that were imported are on the screens that are configured for the projects.