How to find Destination path of deployed web site on Azure App Service Deploy - Azure Slot ?
I need to delete existing old files on a destination specific folder which are generated uniquely on each release(during build process).
This has to be done during pre-deployment.
I used Delete Files Task which is not deleting. Here is YAML.
In Kudu , I am able to see my web site location is D:\home\site\wwwroot\
I wanted to delete files from the path D:\home\site\wwwroot\scripts\libs>
steps:
task: DeleteFiles#1
displayName: 'Delete files from $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(build.artifactstagingdirectory)'
Contents: 'scripts\libs**'
You don't have to manually delete old files on your App Service Instance or its Deployment Slots. When you are using Azure App Service Deploy task you have the option built-in to remove any unused files at the destination (in this case App Service Instance/Deployment slot). Here is how to do it.
On the Azure App Service Deploy task,
Expand Additional Deployment Options.
There make sure Select Deployment Method checkbox is selected
From the Deployment Method drop down, Select Web Deploy
Select the Remove additional files at destination checkbox
If you want to keep any file that is installed with App Service Extensions or WebJobs select Exclude files from the App_Data folder as well
What this will do is it will compare the files that are already at the destination (App Service) with the files that will be copied over from the Artifacts. Then it will delete any file that is not available in the artifacts that you are doing to deploy.
Find Azure slot location in azure App Service Deploy
You may not delete the correct folder.
According to the first image in your question, we could to know you are deleting the file from the folder $(build.artifactstagingdirectory).
As we know, the folder $(build.artifactstagingdirectory) is the local path on the agent where any artifacts are copied to before being pushed to their destination.
Check Build variables for some more details.
However, I do not find any task in your build definition to copy file to the artifacts.
Besides, you said you delete existing old files on a destination specific folder which are generated uniquely on during build process.
So, I am bold to guess that the file you want to delete should be in System.DefaultWorkingDirectory instead of artifacts. But I am not very sure about it, since I could not distinguish folder type from the path D:\home\site\wwwroot\scripts\libs>.
So, to resolve this issue, you can try to delete the file from $(System.DefaultWorkingDirectory).
Or you can use a Inline Powershell task to outcome the value of $(build.artifactstagingdirectory):
Write-Output '$(Build.ArtifactStagingDirectory)'
Then check if the value is match the path of folder you want to delete D:\home\site\wwwroot\scripts\libs>.
Hope this helps.
Related
Environment: Azure PAAS
Activity: Deletion of folders, sub-folders and yml files
As part of our CI-CD process, we delete a folder, sub-folders and yml files. We do this activity in 2 different regions.
The deletion has failed for a set of items in Staging and another set in Production. Surprisingly that has happened only in a particular region (EU-West). The remaining objects have got deleted by the same script successfully.
The error logged is for the Unauthorized access exception.
We have been able to delete the folder, including its content from the Azure command prompt.
As the folder is inside D:, we could not try it from the UI.
Please advice.
I am creating a new Azure Pipeline to deploy .NET Core API app to an App Service in Azure. I am using connection type=publish profile in the pipeline, which is asking for a .pubxml file.
I have already committed the .pubxml file in my Azure repository.
But while giving the path for getting this .pubxml file, I am suspecting that I can't get .pubxml file through build artifacts. Is there any way to get the .pubxml file from azure repos to release pipeline?
I tried with $(Build.SourcesDirectory)\${{ parameters.Location }}\Properties\PublishProfiles\fcmapapi_Dev%20-%20Web%20Deploy.pubxml but no luck.
Any suggestions?
Step 1: Add Azure Repos / Build artifact with an alias to your release pipeline.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/artifacts?view=azure-devops#artifact-sources---tfvc-git-and-github
Add "Build" resources as an artifact:
Add "Azure Repository" as an artifact:
Once, you have added both, the classic release pipeline will look like this:
Step 2: Use the three dots to browse the files / packages.
In Azure DevOps we have the following Azure App Service deploy task in our release pipeline:
This works good but it adds Application settings WEBSITE_RUN_FROM_PACKAGE = 1 for Azure App Service
The web application starts but for some reason /lib/ionic/release/css/ionic.min.css is not loaded with this setting.
If I remove WEBSITE_RUN_FROM_PACKAGE and upload the exact same files via FTP everything works as expected.
I know WEBSITE_RUN_FROM_PACKAGE comes from the .zip file deployment but is there anyway to modify the task to simply upload a folder or do I need to use the FTP upload task then? I know WEBSITE_RUN_FROM_PACKAGE makes wwwroot read-only but what could be causing this? With this setting a GET to the resource simple gives the following error:
The resource you are looking for has been removed, had its name
changed, or is temporarily unavailable.
https://learn.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package
Solved the upload with FTP Upload task
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops
However after doing this I still had the same error.
Went into App Service Console and there I could not see the file at all.
I finally solved it by looking at the file name, /lib/ionic/release/css/ionic.min.css. In our .gitignore file we exclude [Rr]elease/. Adding a ignore with !AppFolder/** solved it so the files were added to git.
Summary: We have Below mentioned release pipelines
1. Release1 -This pipeline will create resources like Application insights, App service plan, Key vault. (ARM files -azuredeploy.json and azuredeployparameters.json)
2. Release2 Pipeline: This pipeline will create resources like App service/Function App using Release1 components like Application insights, App service plan, Key vault. (ARM files -azuredeploy.json and azuredeployparameters.json)
We have multiple micro services In Release2 pipelines,
Environments like Dev, QA, Test .
Each environment has separate resource group.
azuredeployparameters.json all values are same for all services except webapp name.
Issue:If we want change or update any value in all azuredeployparameters.json files in all Release2 pipeline services, We are updating manually.
Kindly suggest the solution on below:
Can we link all our release2 azuredeployparameters.json files to one centralized azuredeployparameters.json file.
If we modify centralized azuredeployparameters.json file, it should update all azuredeployparameters.json files in all release 2 services.
You can put your azuredeployparameters.json in your central/main repo. And if you use release pipelines for instance, you should create build for your central repo and publish azuredeployparameters.json as artifact. You can later use this artifacts in any release pipeline you want. So you can get it Release1 and Release2.
If you use build pipelines also to deploy, you can use multiple repos and get source code (in release 1) from your central repo and repo dedicated to this release. In the same way you have this file available.
If you want to customize file a bit in Relese pipeline you can tokenize you azuredeployparameters.json file and replace those tokens in release. Here you have extension for this.
I am setting up a new Azure DevOps pipeline for my webapp. I can see that the build artifacts are saved in a path called $Build.ArtifactStagingDirectory. Where this path variable is pointing to and how long I can access my artifact?
Also, Does Azure DevOps versions(keep track of all the artifacts built over a time) the artifacts built? If no, how to version my build artifacts?
In the agent there are 3 folders: a, b and s. The variable $(Build.ArtifactStagingDirectory) point to folder a (artifacts), so the path is c:\agent\_work\1\a (if the agent location is c:\agent, the 1 can be another number also, according to how many builds there are, this number is incremental).
The artifacts not saved there! when you build the code all the code and the artifacts exist on folder s (sources), the best practice is to copy only the artifacts to folder a and then use the task "Publish build artifacts", in this task you take the artifacts from folder a and put them on Azure DevOps storage or in your file share (if you use self-hosted agent).
From the Azure DevOps storage / file share the artifacts exist according to your retention policy.
If you save the artifacts in Azure DevOps you can access your artifacts from the build summary page or create a release pipeline. if you save them in a file share you can just access them there or in the release pipeline.
You need to publish artifacts using task as by default they are not published. If you are using yaml just add
# Publish Build Artifacts
# Publish build artifacts to Azure Pipelines/TFS or a file share
- task: PublishBuildArtifacts#1
inputs:
#pathtoPublish: '$(Build.ArtifactStagingDirectory)'
#artifactName: 'drop'
#publishLocation: 'Container' # Options: container, filePath
#targetPath: # Required when publishLocation == FilePath
#parallel: false # Optional
#parallelCount: # Optional
There is configuration how long to keep those artifacts as i remember by default is 30 days and 3 or 5 last builds
You can control how many days you want to keep each build (default 30 days) before deleting it (See
Build and release retention policies). When a build is deleted, the published artifacts also gets deleted.
To version your build artifacts you can use the build number which will keep track.
Where the $Build.ArtifactStagingDirectory is pointing to depends on which publish location you are choosing. See Artifacts in Azure Pipelines