Automation for Jira fails to copy components list to label with error message "The label contains spaces which is invalid"
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When running Automation for Jira rules to copy component values to the labels list, it fails with a "The label 'XXXXXX' contains spaces which is invalid (labels)" error message:
Diagnosis
N/A
Cause
The error message happens because:
The rule is configured to copy the name of the Component Name into the Label using the smart value below:
1
{{issue.components.name}}
Component names may contain multiple words with space in their names, while Label names may not currently include spaces in their names
.
Solution
To solve the Label requirement to not include space characters, while copying the Component values to the Labels list, it's possible to replace the space characters with another character (a hyphen, for example) using an "Additional Fields" custom script.
To duplicate the Components List to the Labels list, changing the space characters to a hyphen using Automation for Jira, please check the steps below:
Create your Automation Rule and configure the conditions to trigger the rule.
Add an Edit issue action.
Expand the drop-down list Choose fields to set... and select the Labels field.
Add the script below to the Additional fields text field.
1 2 3 4 5
{ "fields": { "labels": {{issue.components.name.asJsonStringArray.replace(" ","-")}} } }
The Edit Issue action will look like this:
4. Save the rule and enable it.
The suggested script can duplicate the components items to the label list
Please have in mind that the suggested script will duplicate the Components items to the Label list on the issue, removing any other Label from the issue that it's not on the Component's list.
Results
Please find below an example of the results for the suggested script:
Was this helpful?