Patrick Vibild
Patrick Vibild

Reputation: 435

Create a Azure Instance group from Release pipelines

I am doing a release pipeline and I cant find a way to use a yaml file during the task of my agent.

What is the best practice to create a Azure Container Group during a release pipeline? I have been looking for documentation at microsoft and cant find proper examples.

I was thinking to use a Azure CLI job and create the ACR as I do it locally with the deploy.yaml file.

az container create --resource-group myResourceGroup --file deploy-aci.yaml

deploy.yaml file example

apiVersion: 2018-10-01
location: northeurope
name: e2e
properties:
  containers:
  - name: e2etestcafe
    properties:
      image: n1containers.azurecr.io/e2e/e2etestcafe:latest
      resources:
        requests:
          cpu: 2
          memoryInGb: 8
  - name: customerportal
    properties:
      image: n1containers.azurecr.io/e2e/customerportal:latest
      resources:
        requests:
          cpu: 1
          memoryInGb: 1
      ports:
      - port: 80
  osType: Linux
tags: null
type: Microsoft.ContainerInstance/containerGroups

I cant find anyway to add a file to this job. I am using the wrong tools to do this, is there a way to make a release pipeline with an existing yaml file that I use to create the Container Group?

enter image description here

Upvotes: 0

Views: 177

Answers (1)

Charles Xu
Charles Xu

Reputation: 31424

For your requirements, maybe you're right, the Azure DevOps does not support to create the container instance directly. So that your decision that creates the container instance through the CLI command is right.

Use the CLI as you showed, I don't know which repository do you choose, I assume you use the Azure Repos, so you need to create the YAML file which you use to create the container instance first. Then you can set inline script like this:

enter image description here

The inline script is the only one you need to set, then just save and run it.

Or you can use the pipeline.yaml to set the DevOps job like this:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: AzureCLI@2
  inputs:
    azureSubscription: 'Azure CXP Community Internal Consumption(b83c1ed3-c5b6-44fb-b5ba-2b83a074c23f)'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: 'az container create --resource-group charles --file $(System.DefaultWorkingDirectory)/aci.yaml'

Hope it helps you, and if you have any more questions, just let me know.

Upvotes: 1

Related Questions