Use the Set Variable activity to set the value of an existing variable of type String, Bool, or Array defined in a Data Factory or Synapse pipeline or use the Set Variable activity to set a pipeline return value (preview).
Create a Set Variable activity with UI
To use a Set Variable activity in a pipeline, complete the following steps:
Select the background of the pipeline canvas and use the Variables tab to add a variable:
Search for
Set Variable
in the pipeline Activities pane, and drag a Set Variable activity to the pipeline canvas.
Select the Set Variable activity on the canvas if it isn't already selected, and then select the
Settings
tab to edit its details.
We have expanded Set Variable activity to include a special system variable, named
Pipeline Return Value
, allowing communication from the child pipeline to the calling pipeline, in the following scenario.
You don't need to define the variable, before using it. For more information, see
Pipeline Return Value
Incrementing a variable
A common scenario involving variable is to use a variable as an iterator within an
Until
or
ForEach
activity. In a
Set variable
activity, you can't reference the variable being set in the
value
field, that is, no self-referencing. To work around this limitation, set a temporary variable and then create a second
Set variable
activity. The second
Set variable
activity sets the value of the iterator to the temporary variable. Here's an example of this pattern:
First you define two variables: one for the iterator, and one for temporary storage.
Variables are scoped at the pipeline level. This means that they're not thread safe and can cause unexpected and undesired behavior if they're accessed from within a parallel iteration activity such as a ForEach loop, especially when the value is also being modified within that foreach activity.
Related content
Learn about another related control flow activity: