Azure DevOps — Environments (YAML CICD Pipelines)

Subramani Sundaram (Subu)
4 min readDec 5, 2022

--

An environment is a collection of resources that can be targeted by deployments from a pipeline. Environments can include Kubernetes clusters, Azure web apps, virtual machines, databases. Typical examples of environment names are Dev, Test, QA, Staging, and Production.

The advantages of using environments include the following.

  • Deployment history — Pipeline name and run details are recorded for deployments to an environment and its resources. In the context of multiple pipelines targeting the same environment or resource, deployment history of an environment is useful to identify the source of changes.
  • Traceability of commits and work items — View jobs within the pipeline run that target an environment. You can also view the commits and work items that were newly deployed to the environment. Traceability also allows one to track whether a code change (commit) or feature/bug-fix (work items) reached an environment.
  • Diagnose resource health — Validate whether the application is functioning at its desired state.
  • Permissions — Secure environments by specifying which users and pipelines are allowed to target an environment.

Create an environment

  1. Sign in to our Azure DevOps organization and navigate to our project.
  2. In our project, navigate to the Pipelines page. Then choose Environments and click on Create Environment.

3. After adding the name of an environment (required) and the description (optional), we can create an environment.

4. Resources can be added to an existing environment later as well.

5. Then we can get started by add this newly added environment into the YAML code .

Once after we added that environment into the YAML pipeline , we need to start running it .

We can see the mutiple environments as part of this YAML , basically we are adding the CICD into the YAML file .

From the above environment, we can see the below deployment happened successfully.

Now after this we can log in to Azure portal and then check if the below deployment is successful or not .

Now when we click on the below URL , we can see the basic build and deployment of “HELLO WORLD” application as a sample NodeJS .

We can also manually control when a stage should run using approval checks. You can use approval checks to control deployments to production environments.

Checks are a mechanism available to the resource owner to control when a stage in a pipeline consumes resources.

As the owner of a resource, such as an environment, we can define approvals and checks that must be satisfied before a stage consuming that resource starts. Currently, manual approval checks are supported on environments.

We can control who can create, view, use, and manage the environments with user permissions. There are four roles — Creator (scope: all environments), Reader, User, and Administrator. In the specific environment’s user permissions panel, we can set the permissions that are inherited and we can override the roles for each environment.

  • Navigate to the specific Environment that you would like to authorize.
  • Click on the overflow menu button located at the top-right part of the page next to “Add a resource” and choose Security to view the settings.
  • In the User permissions blade, click on +Add to add a User or group and select a suitable Role.

Pipeline permissions can be used to authorize all or selected pipelines for deployment to the environment.

  • To remove Open access to the environment or resource, click the Restrict permission in Pipeline permissions.
  • To allow specific pipelines to deploy to an environment or a specific resource, click + and choose from the list of pipelines.

This is the basic YAML CICD pipeline without any environment resources such as VM’s or Kubernetes pods.

But that said, we can also do the same way for the other resources as well,

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/environments-virtual-machines?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/environments-kubernetes?view=azure-devops

--

--

Subramani Sundaram (Subu)
Subramani Sundaram (Subu)

Written by Subramani Sundaram (Subu)

Azure MCT | Certified DevSecOps/SRE Practitioner | SAFe4 DevOps Practitioner | Azure 9x Certified | DevOps Institute Trainer | DevOps/Azure Cloud Architect

No responses yet