❯ Guillaume Laforge

Day 3 with Workflows — Variable assignment and expressions

Now that we have multiple steps in our workflow definition, let’s see how we can pass data around, from a step to another.

In a step, you can assign values to variables. Those values can be ints, doubles, strings, or booleans (and also null). Use the assign keyword as follows:

- assignments:
    assign:
        - two:  2
        - pi:  3.14
        - message:  "Hello"
        - bool:  True

Those variables are available in the whole scope of the workflow, and can be accessed in other steps. So let’s see how we can do something with those variables. Let’s add a second step to our workflow definition:

- twoPi:
    return:  ${"Twice  pi  is  " + string(two * pi)}

We are using the ${} notation to create an expression. We’re multiplying two numbers, we’re converting them to a string, and we’re concatenating two strings together, to get our final value.

Note that not all operations are allowed on all types, so you might need to do some conversions with built-in conversion functions like the string() function in our example. There are all sorts of arithmetic operators or boolean logic operators.

For more information, you can read about variable assignments, data types, and expressions. Next time, we’ll also have a look at more complex data types.