Project variable within notification template


how do i access a project or a configuration variable from within a notification template? I need access to a single value. The list of variables available is not what i need.


Hi Thomas,

To output the value of a single variable in a template, iterate through the Variables list with a for loop and use an if statement to select the variable by name. e.g.

{% for variable in Variables  %}
   {% if variable.Name == 'Var1' %}{{variable.Value}}{% endif %}
{% endfor %}

That’s what i was afraid of. Something like Variables[‘myvar’] would be a lot easier to use.

I tested your suggestion before, getting a list of env-vars. Does it actually work for project vars also?

We’re restricted to what is available in the DotLiquid templating language (although it’s possible that we may be able to extend it… ).

The list should include all variables available in the current scope. The scope would depend on the notification type - for build notification types, this will be build variables which are based on configuration, project and application variables.

Thanks Dave,

i confirm it’s working for me. As templates usually get configured only once and then stay forever :wink: it’s fine. No problem.


I’m trying to have the selected branch name (used in a configuration input form when queuing the build) show up in the “build started” notification email:

Branch: {% for variable in Variables %}{% if variable.Name == ‘$source.MyRepo.BranchName$’ %}{{variable.Value}}{% endif %}{% endfor %}

But for some reason it always comes empty, i tried with or without the dollar characters.
Is it possible to use these variables in notifications?

Hi @ktopaz,

You can not use object expressions (delimited with $) in notification templates. You can only use the variables listed in the info panel on the right of the template editor in the form {{TemplateVariableName}}.

There is no Source collection in the available template variables, but you can use the following template code to get the name of the branch that will be built.

MyRepo Branch : {%- for change in BuiltChangeSets -%}
{%- if change.RepositoryName == 'MyRepo' -%}{{change.BranchDisplayName}}{%- endif -%}
{%- endfor -%}