GitLab template variables
Use template variables to create dynamic, reusable dashboards. Instead of hard-coding project IDs or other values, you can create variables that let you switch between different projects, labels, or releases from a drop-down at the top of the dashboard.
For general information about template variables, refer to Templates and variables.
Supported variable types
The GitLab data source supports Query variables for the following resource types:
Create a query variable
To create a query variable using the GitLab data source:
- Navigate to Dashboard settings > Variables.
- Click Add variable.
- Select Query as the variable type.
- Enter a name for the variable (for example,
project). - Select your GitLab data source.
- Set Refresh to On dashboard load.
- Select a Resource Type from the drop-down (for example, Projects).
- Configure any filters for the selected resource type (for example, set Owned to
Trueto list only your projects). - Select a Display Field to determine the text shown in the variable drop-down.
- Select a Value Field to determine the value passed to queries.
- Click Update to save the variable.
Variable fields
Example: Create a project variable
This example creates a variable that provides a drop-down of your GitLab projects, enabling you to switch between projects on a dashboard:
- Add a variable of type Query named
project. - Select your GitLab data source and set Refresh to On dashboard load.
- Select resource type Projects and set Owned to
True. - Set Display Field to
nameand Value Field toid. - Click Update to add the variable to the dashboard.
A drop-down appears at the top of your dashboard with a list of your projects.
To use this variable in a query, enter $project in the Project Id field of any resource type that requires a project ID. When you select a project from the drop-down, the dashboard updates to show data for that project.
Use variables in queries
After creating a variable, reference it in query fields using the $variable_name syntax. For example, if you created a variable named project, enter $project in the Project Id field.
You can use variables in any text input field in the query editor. For more information about variable syntax, refer to Variable syntax.



