How can I run a script in an Azure WebApp container after deployment as part of an Azure DevOps Pipeline using the classic pipelines interface?

HOW TO -️ October 18, 2021

My knowledge of Azure is pretty limited - this is the first project where I've worked with it.

We are deploying Azure webapps in docker containers via an Azure pipeline configured with the classic interface. The pipeline has one agent job that looks like this when I click the "View YAML" button:

ERROR Rendering Code Block

The pipeline isn't really "mine" so I don't want to make any crazy changes but I do have access to edit it and can discuss with the third party admin to make changes if need be.

I need to run a post deployment script to clear caches and such in a container (the app will likely run multiple web containers, it doesn't matter which one the script runs in) after the pipeline finishes.

Unfortunately I just cannot figure out how to do that. Options I've considered:

  • Run it in the container's startup script: containers will also be spun up when the app scales and we don't want to clear the caches in that case
  • Use a container job - this seems to be exactly what I want but unfortunately is not supported in the classic editor. I'd prefer not to rework the devops pipeline entirely since, as mentioned, it's not really "mine"
  • Add a "Docker" task of version 0 with the "Run a Docker command" action and set it to run the "docker exec" command. This seems the most promising but unfortunately there isn't any way I can tell to collect the ID or a name of a just-pushed container (which is a required argument to docker exec). I don't think there's an option to set a name that I can use with docker exec either (I see I can set several tags in the build and push steps but on the image only?), but I'm not too familiar with docker exec either so not 100% sure of that.
  • Add an Azure CLI task that SSHs in to the container and runs a command. Unfortunately it seems like there's no easy way to directly execute a command over Azure's SSH (e.g. via az webapp ssh or az webapp create-remote-connection) so I'm not totally sure whether this would work at all and I suspect it would take many hours of debugging and waiting for containers to deploy to even find out.

Answer

The pipeline that you provided is more of a "build" pipeline - it builds a docker image and publishes it to container registry. How is it then used & deployed? Is it a webapp that automatically picks up published image? something else?

Initializing...