Not so long ago, Microsoft released its consistent hybrid cloud, Azure. Since then, many developers have become its biggest fans. It is no surprise, as Azure delivers outstanding developer productivity, at the same time ensuring comprehensive security. The broad range of services Azure provides, such as analytics, networking, and storage, make the product also a useful tool in many industries from Fortune 500 companies list. Today, we would like to touch on the topic of the Azure templates. What are they, how do they work and why do you need them? Read on to find out!
Azure DevOps YAML templates are YAML files that one can reuse. These can be, for instance, variables, stages, tasks, or jobs. Without the Azure templates, every task would have to be coded repeatedly for every project. Instead, we can define the task just once and use it every time we want to pass in various parameters for similar projects.
Templates increase the readability of the YAML file. Moreover, they help to maintain pipelines in the long term. For example, if a certain task currently has a version number 1, this will be reflected with the @1 at the end of the task. If @2 is released, the only change we need to make is in the template file. Without it, we would have to manually update all instances of the task in every repository using that task.
There is only one condition to using templates, which is the basic knowledge of the Azure Pipelines key concepts, which are steps, stages, and jobs. However, if you do have such an understanding, you can easily speed up your development processes. You can, for instance, build complex templates with a series of the same tasks in a template which you can later on implement several times in various stages of your YAML pipeline.
Additionally, when a template controls what is allowed in a pipeline, such pipeline gains extra security. How? The template dictates the terms other files must follow. You can easily restrict what tasks can be run. Such an option is great for preventing the breach of the company's security policies in cases when someone might want to run a task that violates them.
You can create two types of templates. Let's analyze them below.
Includes template
Such a template allows you to insert content you can reuse with a template. Template used to include content functions like an include directive in various programming languages. The content of one file can be pasted into another file.
Extends template
Such templates control what you allow in a pipeline. In such cases the logic is defined by the template and other files must follow it.
Using template parameters and template expressions will help you discover the full potential of the templates.
By copying one YAML content you will be able to reuse it in another YAML. One logic for multiple places of application is a substantial saving of time, energy, and money.
If you want to reuse steps across several jobs, inserting a template is the best way to do it. It is also possible to add other steps to the job that are not reused.
The situation with jobs is similar to the one with steps. Pay attention to removing the job name in the template file, so you do not come across any conflict.
The same as the above applies to stages.
You can define variables in one YAML and include them in another template. This is especially helpful when you wish to have all variables stored in one file. However, the template you use to include variables in a pipeline can only be used to define variables. Advanced logic and the use of steps can be used when extending from a template. To restrict the type, choose using parameters not variables.
Parameters can be passed to variables with templates. When consuming the template in your pipeline, specifying values for the template parameters is necessary.
When we consider the file that does the including, the template paths can be relative to the repository or an absolute path within that repository.
You must start your template path with a / to use an absolute path. Every other path is a relative path.
Templates can be kept within other repositories. If you, for instance, want all app pipelines to use one main pipeline, put a pipeline in the core repository for reference. This template can then be used in many pipelines. The location of the core repository will be provided by resources specification and you can use @ and a chosen name every time you want to refer to it.
You resolve repositories only one time, and it is at the time of the pipeline start-up. Once that is done, that one resource you will use during the whole pipeline. You only use the template files. When you expand such templates, the final pipeline runs as if it were set in the source repo. In this situation, you will not be able to use the template repo scripts in the pipeline.
Pinning to ref is imperative if you wish to use a certain, fixed template version. The refs can either be branches (refs/heads/<name>) or tags (refs/tags/<name>). Pinning a specific commit requires creating a tag pointing to that commit first. Only then you can pin to that tag.
Using Azure job template and step template are only a few ways of time-saving options you can use in managing your project. Another example is integrating Azure with appropriate third-party apps. One of the most noteworthy ones is TimeCamp. This is not a standard time-tracking software, which simply records the times of your tasks. TimeCamp lets you choose the settings, which will generate the most accurate and custom data and help you understand your business better. What exactly can you get thanks to the TimeCamp integration with Azure?
One-click timer - starting and stopping time measurements with one, easy-to-locate TimeCamp timer;
Time tracking using keyword- using a chosen word to automatically track time;
Copying of time entries - recurring work patterns can be copied;
Website and app monitoring - productive time is monitored based on the time spent within certain apps and websites;
Idle and private time tracking easy and accurate client billing thanks to the measurement of working time only;
Attendance monitoring - effortless automatic tracking of start, finish of work, and break times;
Productivity reports - generate tailored reports to get insightful data to boost your team’s efficiency, productivity, and performance.
TimeCamp has a forever free plan that offers unlimited projects and uses for unlimited users. For more advanced features, get one of our premium plans with a free 14-day trial!