Use expressions with database instance tags
Look up database instances by tag, or read the value of a tag on an instance, and use the result in your pipeline.
When you create a database instance in Harness, you can add tags to it. Harness Database DevOps provides two expressions that read those tags while a pipeline runs:
dbInstancesByTagreturns all the instances in a schema that have a given tag.dbInstanceTagValuereturns the value of a tag on one instance.
Use them to run a step on every instance in an environment, or to run a stage only when an instance carries a certain tag. Both work in JEXL and CEL.
Add tags to your instance
Add tags when you create or edit a database instance in DB Instances. A tag is either a key on its own, such as allowAutomatedDeployment, or a key-value pair, such as env:prod.

Tags belong to the instance, not to the schema.
Use an expression in a step
Open the step or stage setting you want the expression to drive.
Change the input type from Fixed value to Expression.
Enter the expression, for example
<+dbInstancesByTag.getValue("mySchema", "env:prod")>.

Expression reference
dbInstancesByTag
Returns the identifiers of all database instances in a schema that have the tag.
schema
The database schema to search.
tagQuery
The tag to match. Use a key, such as env, or a key-value pair, such as env:prod.
If no instance matches, you get an empty list.
Example
dbInstanceTagValue
Returns the value of a tag on a specific instance.
schema
The database schema the instance belongs to.
instance
The database instance to check.
tagKey
The key of the tag you want the value of.
If the tag isn't on the instance, you get an empty string.
Example
If instance1 has the tag env:prod, this returns prod.
CEL
Add the cel. prefix to call either expression from CEL:
Examples
Run a step on every instance with a tag
If your schema has four instances tagged env:prod, use dbInstancesByTag as the items in a repeat strategy. The stage runs once per instance.
Reference the current instance with <+repeat.item>.
Go to Looping strategies for more about repeat strategies.
Filter the list by a second tag
Combine both expressions. Loop over the env:prod instances, then check each one's region tag to decide whether to run the step:
Run a stage only when a tag matches
Select the stage, then go to Advanced > Conditional Execution.
Select Execute this stage only if the following JEXL condition is true.
Enter a condition, for example:
Harness skips the stage when the condition is false, instead of failing it.
Go to Conditional executions for stages and steps for more about conditions.
Next steps
Last updated
Was this helpful?