Azure DevOps deployment pipelines offer three types of jobs: agent job, deployment group job, and agentless job. However, YAML pipelines require an alternative approach as they lack direct support for deployment group jobs. Virtual machine resources in environments are utilized to achieve similar functionality as deployment groups, and this blog explains how to do it.
Prerequisites:
- Azure DevOps environment provisioned with virtual machine resources.
- Fundamental understanding of pipeline configuration
As a prerequisite, an environment called Test-dev has been provisioned and a virtual machine has been added to it.
A tag called "dev" has been added to the virtual machine.
To perform deployment group deployments, create a YAML pipeline with the following job structure. Provide the environment name, resourceType, and tags.
jobs:
- deployment: VMDeployment
displayName: CD
environment:
name: Test-dev
resourceType: VirtualMachine
tags: dev
strategy:
runOnce:
deploy:
steps:
- checkout: self
When the pipeline run, the correct virtual machine will be assigned as the pipeline agent, as shown in the below image.
Below is the full pipeline script. Virtual machines that match the specified tag will act as the deployment
group, and a text file will be created at C:\temp\test.txt inside the virtual machine.
trigger: branches: include: - develop pool: name: "Azure Pipelines" vmImage: ubuntu-20.04 stages: - stage: Deployment displayName: Deploy to VM jobs: - deployment: VMDeployment displayName: CD environment: name: Test-dev resourceType: VirtualMachine tags: dev strategy: runOnce: deploy: steps: - checkout: self - task: PowerShell@2 displayName: createfile inputs: targetType: 'inline' script: 'New-Item C:\temp\test.txt'
No comments:
Post a Comment