0

I am writing an Azure Pipeline framework in YAML which will be used on multiple projects, each with its own environment variables. I am now wondering whether the best option is to define these variables in variable groups or to use YAML templates.

The Requirements

The requirements are as follows

  1. Values should not bleed between projects.
  2. Values do not need to be versioned.
  3. It is an advantage if values are easy to access and change.
  4. The variable sets need to have the same structure for every project, i.e. group and variable names must follow a specific pattern.
  5. It must be possible to detect whether a variable definition is missing.

Both solutions seem to conflict with the requirements.

Variable Groups

While variable groups naturally satisfy requirements 1-3, requirements 4 and 5 seem a little more complicated. For requirement 4, it is up to the developer to make sure the structure remains the same between projects, which can become a tedious and error-prone activity when the collection of groups grows. Regarding requirement 5, I guess it is possible to write a template to make sure all the necessary variables are defined, although it seems to me this leads to bloat.

YAML templates

What I have in mind with this solution is to create unfilled YAML templates to define the required values, guiding the developers. This way, they will get syntax errors if they forget some definitions. Hence requirements 1, 4, and 5 are satisfied. The last two are less clear, however. For requirement 2, versioning is not preferred but is not an issue either. And regarding requirement 3, with this solution, users will have to have a basic understanding of the repository and YAML syntax to read and change values.

What is the recommended solution in this scenario? Are there best practices guidelines to follow, or perhaps some other solution to this problem? Help is much appreciated!

1 Answer 1

0

I wound up using YAML templates for a collection of reasons which I list below, in addition to the arguments made in the question body.

  • YAML template variables may also be expanded at compile-time, as opposed to variable groups which may only be expanded at runtime.
  • YAML template variables may be documented.
  • YAML templates offer the added functionality of scripting.
  • YAML templates offer more freedom in terms of the structure of the data.
  • With YAML templates the variables live closer to the pipeline scripts, making development swifter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.