Setting up and managing Azure DevOps environments is a crucial step in ensuring the smooth operation of your software development pipeline.
To create an environment in Azure DevOps, you can use the "New Environment" button in the Environments section of your project. This will prompt you to enter a name for the environment and select the type of environment you want to create.
You can also create environments from Azure Pipelines, by adding an "Environment" task to your pipeline. This allows you to define the environment as part of the pipeline itself.
Environments in Azure DevOps can be configured to automatically scale based on demand, which can help reduce costs and improve efficiency. This is done by setting up a scaling policy in the Environment settings.
Prerequisites
To get started with Azure DevOps environments, you'll need to meet a few prerequisites.
You'll need an Azure DevOps organization and project set up. This will be the foundation for your environments.
You'll also need to have the Creator role for environments in your project. This role grants you the necessary permissions to create and manage environments.
Here are the specific prerequisites you'll need to meet:
- An Azure DevOps organization and project.
- The Creator role for environments in your project.
Target a Job
Targeting a job in Azure DevOps Environments is a powerful feature that allows you to run a deployment job against a specific environment or resource within that environment.
You can target an entire environment group of resources from a deployment job, as shown in the YAML snippet in Example 1.
To target a specific environment resource, you can scope the deployment target to a particular resource within the environment, which automatically inherits the service connection details from the resource the deployment job targets.
In Example 2, the value for the kubernetesServiceConnection automatically passes down to the task from the environment.resource input.
You can also use a deployment task to target a complete environment, as demonstrated in Example 3.
If you want to limit the deployment's goal to a certain environment resource, you can do so, which allows you to keep a deployment history log for a particular environment resource.
The service connection information is automatically inherited by the deployment job's steps from the resource it is targeting, as stated in Example 4.
Here are some key points to keep in mind when targeting a job:
- Targeting an environment from a deployment job allows you to run a collection of steps against the environment.
- Targeting a specific environment resource allows you to record deployment history on the specific resource.
- The service connection information is automatically inherited by the deployment job's steps from the resource it is targeting.
Approval and Security
Approval and Security is a crucial aspect of Azure DevOps Environments. You can secure your environments by setting user permissions and pipeline permissions.
As an environment owner, you can manually control when a stage should run by using approval checks. This is especially useful for controlling deployments to production environments. The environment Creator, Administrator, and User roles, but not the Reader role, can manage approvals and checks.
To manage approvals and checks, navigate to the specific Environment, click on the overflow menu button, 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. There are four roles available: Creator, Reader, User, and Administrator.
You can also restrict permission in Pipeline permissions to remove open access on the environment or resource. This allows you to allow specific pipelines to deploy to the environment or to a specific resource. To do this, click the Restrict permission in Pipeline permissions and then click + to choose from the list of pipelines.
Here are the available roles and their scopes:
- Creator: all environments
- Reader: no scope
- User: no scope
- Administrator: no scope
Manual Approval
Manual approval is a powerful tool in Azure Pipelines that allows you to control deployments to production environments. You can use manual approval checks to ensure that only authorized personnel can approve a stage in a pipeline.
To use manual approval checks, you need to be in one of the following roles: Creator, Administrator, or User. The Reader role does not have the necessary permissions. As the owner of an environment, you can define approvals and checks that must be satisfied before a stage consuming that resource can begin.
You can add manual approval checks by navigating to the specific environment you want to authorize, clicking on the overflow menu button, and choosing Security. From there, you can add a user or group and select a suitable Role.
The four available roles are Creator, Reader, User, and Administrator. The Creator role has scope over all environments, while the Reader role has limited permissions. The User and Administrator roles have varying levels of control over environment settings.
Here are the roles and their corresponding permissions:
By using manual approval checks, you can ensure that only authorized personnel can approve a stage in a pipeline, and that all necessary checks are met before deployment.
Security
Securing your environments is a top priority, and Azure Pipelines makes it easy to control who has access to your resources. You can restrict permission on the environment or resource by selecting Restrict permission in Pipeline permissions.
To do this, go to the Pipeline permissions panel of the Security page and select Restrict permission. This will remove open access to the environment or resource.
If you want to allow specific pipelines to deploy to the environment or a specific resource, you can select + and choose from the list of pipelines. This is a great way to control which pipelines have access to your resources.
In addition to pipeline permissions, you can also control who can create, view, use, and manage environments with user permissions. There are four roles: Creator, Reader, User, and Administrator.
Here's a breakdown of the roles:
By controlling who has access to your resources and environments, you can ensure that only authorized personnel can make changes and deployments.
Viewing and Managing
You can view deployment history by selecting the Deployments tab in the Azure Pipelines Environments section. This helps identify all pipelines that affect an environment and visualize the sequence of deployments by each pipeline.
To drill down into job details, select the Changes and Work items tabs on a deployment page. The Changes tab shows a list of commits, with the first listing including all commits to that point and subsequent listings including just the changes for that job.
Here are the details you can expect to see on the Changes and Work items tabs:
- Changes tab: lists of commits with multiple results for commits tied to the same job
- Work items tab: lists of work items with multiple results for work items tied to the same job
Run Details
In the pipeline run details, you can see all environments that were targeted by deployment jobs of a pipeline run.
The Environments tab is available, but only if you're not using an Azure Kubernetes Service (AKS) private cluster.
You can install agents on your own servers using virtual machine (VM) resources for rolling deployments.
The deployment history view in an environment allows you to trace the deployment history from your virtual machine to your pipeline.
View History
Viewing deployment history is a crucial step in understanding how your pipelines are performing. You can select the Deployments tab in the Azure Pipelines Environments section to view deployment history.
To drill down into job details, select the Changes and Work items tabs on a deployment page. The tabs show lists of commits and work items that deployed to the environment.
Each list item represents new items in that deployment. On the Changes tab, the first listing includes all the commits to that point, and the following listings include just the changes for that job. If multiple commits are tied to the same job, there are multiple results on the Changes tab.
Similarly, if multiple work items are tied to the same job, there are multiple results on the Work items tab.
Here's a quick rundown of what you can view in the deployment history:
- View jobs from all pipelines that target a specific environment
- Drill down into job details using the Changes and Work items tabs
- View lists of commits and work items that deployed to the environment
You can also view deployment history with Azure Resource Manager, which allows you to look up particular operations from previous deployments to see what resources were used.
Usage and Benefits
Azure DevOps Environments provide a range of benefits, including standardization and collaboration, which allows teams to easily create and manage on-demand environments using Infrastructure as Code (IaC) templates stored in source control.
This promotes collaboration and inner-sourcing of templates from source control repositories, making it easier to work together and share knowledge.
Azure DevOps Environments also enable platform engineering teams to curate environment definitions, enforcing enterprise security policies and mapping projects to Azure subscriptions, identities, and permissions by environment types.
This ensures compliance and governance across the organization, reducing the risk of security breaches and non-compliance.
Here are the key benefits of Azure DevOps Environments:
- Standardization and collaboration: Capture and share IaC templates in source control.
- Compliance and governance: Enforce enterprise security policies and map projects to Azure subscriptions.
- Project-based configurations: Organize environment definitions by application type.
- Worry-free self-service: Enable development teams to quickly create app infrastructure resources.
- Integration with your existing toolchain: Use APIs to provision environments from CI tools and IDEs.
Usage Scenarios
Azure Deployment Environments are highly versatile and can be applied to a wide range of scenarios.
Common usage scenarios include Azure Deployment Environments, which are often used in DevOps to streamline development and deployment processes.
In a DevOps setting, Azure Deployment Environments help teams quickly create and manage multiple environments for testing and staging.
These environments are essential for ensuring that applications are thoroughly tested before being deployed to production, reducing the risk of errors and downtime.
Azure Deployment Environments also facilitate the creation of isolated environments for different projects or teams, allowing for greater flexibility and control.
By separating environments, teams can avoid conflicts and ensure that each project has a dedicated space for development and testing.
This approach also enables teams to easily replicate production environments for testing and debugging purposes.
In summary, Azure Deployment Environments provide a flexible and efficient way to manage multiple environments, streamlining the development and deployment process.
Benefits
With Azure Deployment Environments, you can create, configure, and manage environments in the cloud with ease. This platform provides several benefits that make it an attractive choice for businesses.
Standardization and collaboration are key benefits of Azure Deployment Environments. You can capture and share IaC templates in source control within your team or organization, making it easy to create on-demand environments and promote collaboration through inner-sourcing of templates from source control repositories.
Compliance and governance are also major advantages. Platform engineering teams can curate environment definitions to enforce enterprise security policies and map projects to Azure subscriptions, identities, and permissions by environment types.
Organizing environment definitions by application type is another benefit. This allows development teams to quickly and easily create app infrastructure resources using preconfigured templates and track costs to stay within budget.
Azure Deployment Environments also integrates well with your existing toolchain. You can use APIs to provision environments directly from your preferred CI tool, IDE, or automated release pipeline, or use the comprehensive command-line tool.
With Azure, you can design, launch, and manage apps more rapidly and easily without needing to purchase and/or maintain the underlying infrastructure. Its integrated cloud resources are easily configurable to meet your specific requirements while meeting all of your security and compliance requirements.
Here are some benefits of using Azure Deployment Environments:
- Standardization and collaboration
- Compliance and governance
- Project-based configurations
- Worry-free self-service
- Integration with your existing toolchain
Frequently Asked Questions
What are the environment names for DevOps?
Azure DevOps environments include names like Dev, Test, QA, Staging, and Production, but are not available in Classic pipelines. For Classic pipelines, deployment groups offer a similar functionality.
What are Azure deployment environments?
Azure deployment environments are self-service, project-based templates for deploying environments at any stage of development. They enable developers to easily set up and manage environments for various development stages.
How many environments are in DevOps?
We recommend a standard setup with three environments: development, staging, and production. This setup is a great starting point for your DevOps journey, but there are many other options to explore.
Sources
- https://learn.microsoft.com/en-us/azure/devops/pipelines/process/environments
- https://learn.microsoft.com/en-us/azure/deployment-environments/overview-what-is-azure-deployment-environments
- https://k21academy.com/microsoft-azure/az-400/azure-devops-environments-how-to-setup-devops-environment-approval-checks-azure-devops-pipeline/
- https://github.com/microsoft/azure-pipelines-yaml/blob/master/design/environment.md
- https://mercuryworks.com/blog/creating-a-multi-stage-pipeline-in-azure-devops
Featured Images: pexels.com