1
votes

I have a web application hosted in Azure and some files are in the wwwroot folder. I have others outside of wwwroot, actually in a directory called components at the same level.

So far I have been updating the files manually using Kudu console, dropping a ZIP file in components. I have started moving my process to Azure Pipelines; I managed to configure a build pipeline that automatically produces and compresses the files/artifacts to drop in components.

Now I am trying to configure the release pipeline to deploy the files from the build to components. The thing is I am unable to find a task, default or from the Marketplace, that allows me to configure the target path as components; they all deploy against wwwroot by default.

Is there any sort of task or script to achieve this?

This is the first time I am facing the setup of the CI/CD with Azure Pipelines, maybe I am overlooking something.

1

1 Answers

5
votes

You can achieve this using scripts calling Kudu api. You need to add an azure powershell task in your release pipeline and run kudu api. Below scripts is for example.

1, scripts to create a directory components

$WebApp = Get-AzWebApp -Name '<appname>' -ResourceGroupName '<resourcegroupname>'
[xml]$publishingProfile = Get-AzWebAppPublishingProfile -WebApp $WebApp
# Create Base64 authorization header
$username = $publishingProfile.publishData.publishProfile[0].userName
$password = $publishingProfile.publishData.publishProfile[0].userPWD
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$bodyToPOST = @{  
command = "md components"
                 dir = "D:\home\site"  
}  
# Splat all parameters together in $param  
$param = @{  
            # command REST API url  
            Uri = "https://<appname>.scm.azurewebsites.net/api/command"  
            Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}  
            UserAgent = "powershell/1.0"  
            Method = "POST"  
            Body = (ConvertTo-Json $bodyToPOST)  
            ContentType = "application/json"  
}  
# Invoke REST call  
Invoke-RestMethod @param  

Above scripts will first get the username and password from your app's publishprofile which will be used later as anthentication in calling kudu api. And the api will run your self-defined command to make directory components in "d:\home\site" enter image description here

2, Deploy your app using kudu api.

When the components directory is created, you can invoke kudu api to deploy your app to components directory. Please refer to below example.

$param = @{  
            # zipdeploy api url  
            Uri = "https://<appname>.scm.azurewebsites.net/api/zip/site/components"  
            Headers = @{Authorization=("Basic {0}" -f $base64AuthInfo)}  
            UserAgent = "powershell/1.0"  
            Method = "PUT"  
            # Deployment Artifact Path  
            InFile = "$(System.DefaultWorkingDirectory)\<artifacts_alias>\drop\<artifacts_name>.zip"  
            ContentType = "multipart/form-data"  
}  
# Invoke REST call  
Invoke-RestMethod @param  

The value InFile should point to location of the artifact file which is downloaded by your release pipeline. Usually it is located in "$(System.DefaultWorkingDirectory)\<artifacts_alias>\drop\<artifacts_name>.zip"

For more information about Kudu Api, you can refer to this blog.