Azure Pipeline Part 14 – Environments Deployment Jobs

Azure Pipeline Part 14 – Environments Deployment Jobs

Azure Pipeline Part 14 – Environments Deployment Jobs

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

You can create an Environment for your application deployment In Azure Pipeline. An environment lets you manage your application deployment in a central place with optional feature like adding approval in your pipeline or monitoring your entire application deployment pipelines.

Using an environment, you can bring all your deployment pipeline with respective resources in a central place to manage your deployments. For example, suppose you application uses multiple pipelines for deployment, using environment you can track all the pipelines status in a single place or manage security and add approvals. An Environment is used in conjunction with a deployment job to manage your application deployments.

You can put your application deployment steps in a special type of job called a deployment job. A deployment job is a collection of steps that are run sequentially against an environment. Using deployment jobs, you get the deployment history across pipelines, down to a specific resource and status of the deployments for auditing and define the deployment strategy.

Note: A deployment job doesn’t automatically clone the source repo. You can checkout the source repo within your job with checkout: self.

Azure Pipeline Part 14 – Environments Deployment Jobs

Prerequisites:

Setup:

Azure Pipelines – Environments:

An environment is a collection of resources that you can target with deployments from a pipeline. Typical examples of environment names are Dev, Test, QA, Staging, and Production.

Azure Pipelines – Environments Syntax:

Azure Pipelines – Deployment Jobs:

A deployment job is a collection of steps to be run sequentially. A deployment job can be used to target an entire environment (group of resources) or a particular resource within the environment.

Azure Pipelines – Deployment Jobs Syntax:

Azure Pipelines – Environment and Deployment Jobs Example:

Step 1: Create a new Environment in Azure Pipeline.

Login to your Azure DevOps portal and navigate to Azure Pipeline for the Project that we have created during the setup.

Click on “Environment” under Azure Pipeline and click “Create environment”.

Azure Pipeline Part 14 – Environments Deployment Jobs

Provide a name for your environment and select a resources type and click “Next”.

Azure Pipeline Part 14 – Environments Deployment Jobs

Note: Azure Environment supports Kubernetes and Virtual machines as resources type and in this demo, we are going to use a virtual machine with Linux OS.

Select the OS for your resources and copy the script that you need to execute in your Linux machine.

Azure Pipeline Part 14 – Environments Deployment Jobs

Log in to your Linux machine and execute the script that you previously copied. Below is the script for your reference –

This script will download the Azure DevOps agent binary and install and configure in interactive mode. Optionally you can add a tag when prompted.

Once you create the environment and resource it will be visible in your Azure DevOps portal.

Azure Pipeline Part 14 – Environments Deployment Jobs

Next, we are going to use this environment and resource in a deployment job in Azure Pipeline.

Step 2: Create an Azure Pipeline config YAML file which uses a deployment job to deploy in the environment created in previous step.

Note: You might need to provide some additional access to your Azure Pipeline in order to use the new environment and resources.

Azure Pipeline Part 14 – Environments Deployment Jobs

Next, we will add manual approval in Azure Pipeline.

Azure Pipeline – Manual Approval:

Step 1: Login to Azure DevOps portal and navigate to the environment created previously. From the options, click “Approval and checks”.

Azure Pipeline Part 14 – Environments Deployment Jobs

Step 2: Click on the “Approvals”

Azure Pipeline Part 14 – Environments Deployment Jobs

Step 3: Add an approver and click “Create”.

Azure Pipeline Part 14 – Environments Deployment Jobs

Step 4: Do some update in pipeline YAML file and push the changes.

If you now check the Azure Pipeline UI, you will see that the pipeline is waiting for approval. The pipeline will not get executed till its approved by the approver.

Step 5: Approve the pipeline.

Azure Pipeline Part 14 – Environments Deployment Jobs

Azure Pipeline Part 14 – Environments Deployment Jobs

Once approved, you pipeline will start execution.

Clean up:

Hope you have enjoyed this article. To know more about Azure DevOps, please refer below official documentation

https://docs.microsoft.com/en-us/azure/devops/?view=azure-devops

Leave a Reply

Close Menu