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:

  name: Azure Pipelines
- task: Docker@0
  displayName: 'Build an image'
    azureSubscription: '<omitted>'
    azureContainerRegistry: '{"loginServer":"<omitted>", "id" : "<omitted>"}'
    dockerFile: Dockerfile
    includeSourceTags: true
    includeLatestTag: true

- task: Docker@0
  displayName: 'Push an image'
    azureSubscription: '<omitted>'
    azureContainerRegistry: '{"loginServer":"<omitted>", "id" : "<omitted>"}'
    action: 'Push an image'
    includeSourceTags: true
    includeLatestTag: true

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.
  • 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?
    – qbik
    Commented May 18, 2021 at 10:27

1 Answer 1


a. In the Azure DevOps portal, go to the "Pipelines" section.

b. Click on "Releases" and then create a new release pipeline.

c. Define your release pipeline stages for deploying your Azure Web App.

d. In the stage where you want to run the post-deployment script, add an "Azure App Service Deployment" task.

e. Configure the task with your Azure subscription and select your Web App.

f. In the "Additional Deployment Options" section, you can specify a "Script" to run post-deployment. Provide the path to your script within your repository.

For example, if your script is in a folder called "scripts" at the root of your repository, you would specify the "Script" field as $(System.DefaultWorkingDirectory)/scripts/your-script.sh for a Bash script.

g. Complete the task configuration and save your pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.