<p>a. In the Azure DevOps portal, go to the &quot;Pipelines&quot; section.</p>
<p>b. Click on &quot;Releases&quot; and then create a new release pipeline.</p>
<p>c. Define your release pipeline stages for deploying your Azure Web App.</p>
<p>d. In the stage where you want to run the post-deployment script, add an &quot;Azure App Service Deployment&quot; task.</p>
<p>e. Configure the task with your Azure subscription and select your Web App.</p>
<p>f. In the &quot;Additional Deployment Options&quot; section, you can specify a &quot;Script&quot; to run post-deployment. Provide the path to your script within your repository.</p>
<p>For example, if your script is in a folder called &quot;scripts&quot; at the root of your repository, you would specify the &quot;Script&quot; field as $(System.DefaultWorkingDirectory)/scripts/your-script.sh for a Bash script.</p>
<p>g. Complete the task configuration and save your pipeline.</p>

CC BY-SA 4.0
2023-10-25T19:04:19.393Z
2023-10-25T19:04:19.393Z
geeky_girl
<p>My knowledge of Azure is pretty limited - this is the first project where I've worked with it.</p>
<p>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 &quot;View YAML&quot; button:</p>
<pre><code>pool:
  name: Azure Pipelines
steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    azureSubscription: '&lt;omitted&gt;'
    azureContainerRegistry: '{&quot;loginServer&quot;:&quot;&lt;omitted&gt;&quot;, &quot;id&quot; : &quot;&lt;omitted&gt;&quot;}'
    dockerFile: Dockerfile
    includeSourceTags: true
    includeLatestTag: true

- task: Docker@0
  displayName: 'Push an image'
  inputs:
    azureSubscription: '&lt;omitted&gt;'
    azureContainerRegistry: '{&quot;loginServer&quot;:&quot;&lt;omitted&gt;&quot;, &quot;id&quot; : &quot;&lt;omitted&gt;&quot;}'
    action: 'Push an image'
    includeSourceTags: true
    includeLatestTag: true
</code></pre>
<p>The pipeline isn't really &quot;mine&quot; 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.</p>
<p>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.</p>
<p>Unfortunately I just cannot figure out how to do that. Options I've considered:</p>
<ul>
<li>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</li>
<li><a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/process/container-phases?view=azure-devops" rel="nofollow noreferrer">Use a container job</a> - this seems to be <em>exactly</em> 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 &quot;mine&quot;</li>
<li>Add a &quot;Docker&quot; task of version 0 with the &quot;Run a Docker command&quot; action and set it to run the &quot;docker exec&quot; 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.</li>
<li>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 <code>az webapp ssh</code> or <code>az webapp create-remote-connection</code>) 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.</li>
</ul>

CC BY-SA 4.0
2021-05-18T10:27:34.537Z
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
<azure-devops><azure><azure-pipelines>
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?
Dylan
# 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?

(Asked by: username_0 on 2020-08-13)

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:
pool:
  name: Azure Pipelines
steps:
- task: Docker@0
  displayName: 'Build an image'
  inputs:
    azureSubscription: ''
    azureContainerRegistry: '{"loginServer":"", "id" : ""}'
    dockerFile: Dockerfile
    includeSourceTags: true
    includeLatestTag: true

- task: Docker@0
  displayName: 'Push an image'
  inputs:
    azureSubscription: ''
    azureContainerRegistry: '{"loginServer":"", "id" : ""}'
    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.

**Tags:** azure-devops, azure, azure-pipelines

> **Comments:**
> **username_1**: 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?  

---

## 1 answers

### Answer by username_2 on 2023-10-25. Score: 0

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.


---

