4

I have an Azure release pipeline that uses an Azure Web App for Containers task to deploy a docker image on an Azure App Service.

The image is specified in the form of some_image:$(Build.BuildId). The pipeline works as intended and successfully updates the App Service with the latest built of the image.

I want from an other release pipeline to execute a docker run command using that image. I've noticed that version 1 of the Docker task allows me to execute such a docker run command on a docker image (no idea why run is missing from version 2), but how can I specify the docker image? How can I get which image is the currently deployed on that App Service?

egwspiti
  • 957
  • 5
  • 10
  • I am not sure why you are trying to do it in the same step, but this should help https://stackoverflow.com/questions/63583510/how-to-run-a-docker-container-in-azure-pipeline – Sajeetharan Jan 16 '21 at 18:33
  • I'm not trying to do it in the same step, I want to use a different pipeline for it. Unfortunately it doesn't help, I don't want to use the latest built image for the run command, I want to use the latest deployed image. – egwspiti Jan 16 '21 at 18:46
  • in that case you can pass the container registry and then the image name, whats difficult there – Sajeetharan Jan 16 '21 at 18:48
  • but which image version is currently deployed? – egwspiti Jan 16 '21 at 18:59
  • Do you need to know what is the current version deployed in Azure Web App? Are you OK to use AZ CLI or Powershell script to get this information? – Andriy Bilous Jan 16 '21 at 19:59
  • If there's a way to use az cli or powershell in an azure release pipeline, I think it's OK – egwspiti Jan 16 '21 at 20:55
  • Is this documentation helpful: https://learn.microsoft.com/en-us/azure/app-service/configure-linux-open-ssh-session? – Cece Dong - MSFT Jan 18 '21 at 09:53
  • @CeceDong-MSFT it lists various ways except the one I'm looking for, how to do it via a release pipeline, so unfortunately it's not that helpful – egwspiti Jan 19 '21 at 19:34
  • @egwspiti You may add powershell script task in your pipeline to invoke Azure CLI command: https://learn.microsoft.com/en-us/azure/app-service/configure-linux-open-ssh-session#open-ssh-session-from-remote-shell. – Cece Dong - MSFT Jan 20 '21 at 10:04

2 Answers2

1

Might be too late now, but what you want to do is to get the value of LinuxFXVersion (if you're running docker on Linux) property from Azure Resource Explorer.

Using a combination of Azure PowerShell and CLI, you can have these commands to retrieve the current image running on your web app:

 $webAppProperties = (az webapp config show --subscription "<subscription-id>" --resource-group "<resource-group-name>" -n "<webapp-name>") | ConvertFrom-Json
 $webAppProperties.linuxFXVersion

Assuming you have the right permissions to your subscription from Azure Pipelines, you should be able to use this information for the next steps.

0

You can either use PowerShell or Shell script in the YAML pipeline. Since you already know the container registry and the image name, just use the below command to get the latest version

az acr repository show-tags -n MyRegistry --repository MyRepository --top 1 --orderby time_desc --detail

https://learn.microsoft.com/en-us/cli/azure/acr/repository?view=azure-cli-latest#az_acr_repository_show_tags

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • 2
    But I don't want the latest version, I want the version that's currently deployed at the App Service – egwspiti Jan 17 '21 at 15:19
  • https://learn.microsoft.com/en-us/answers/questions/192684/finding-the-container-id-of-a-customer-docker-imag.html – Sajeetharan Jan 17 '21 at 16:14
  • I can ssh into my App Service container via webssh and get the deployed version but how can I do this from the release pipeline? – egwspiti Jan 17 '21 at 18:06