Concatenate strings variables in script

Hello,

I want to create a script where at different steps I would like to amend a given string variable so that I can send it at the end within a notification.

Let’s say I define a first variable :

  • variables:
    mystring: line 1

Then later I want to add some text to the variable mastering.

I create a second variable string-to-add:

  • variables:
    string_to_add: line 2

Then what is the proper syntax to concatenate the variable string_to_add to the initial variable mystring ?

For example the following syntax does not seem to work:

  • variables:
    newstring2: {{mystring}} + {{string-to-add}}

Thanks

Eric

How about this?

newstring2: {{ mystring + string-to-add }}

It is preferable to use ~ rather than + for string concatenation.

Thanks for replies. I have tested these 2 options, but what is weird is that in both cases after saving, the YAML editor transformed the line in:

newstring2:
    "[object Object]": null

SO it seems it does like the syntax.

I am editing in the web interface using Firefox.

Quote your single line templates:

newstring2: "{{ mystring ~ string-to-add }}"
1 Like

I finally got it !
I had to put the expression {{ mystring ~ string_to_add }} between double quotes:

variables:
string_to_add: line 2
newstring2: “{{ mystring ~ string_to_add }}”

Is OK. BTW, both + and ~ seem to work.

Anyhow, thx for the initial tip.

Eric

1 Like