问题描述
我们在Azure中有两个不同的应用程序服务应用程序,它们使用相同的代码,而不是3个配置文件。我目前正在使用Azure应用服务部署任务通过发布管道进行部署(跳过其他参数中的配置文件)。
这3个配置文件放置在另一个文件夹azure devops vsts存储库中的2个不同文件夹中。
在发布管道中的部署任务之后,是否还有其他任务/ powershell脚本/ ftp上传来复制3个配置和设置文件。
解决方法
作为解决方法,您需要将配置文件所在的仓库签出到当前源。如果您正在使用yaml管道,则可以在yaml文件中定义checkout step。这样,除了用于存储YAML管道的存储库之外,还可以获取并检出其他存储库。如果您使用的是经典管道,则可以通过writing a script:git clone https://github.com/Microsoft/TypeScript.git
来完成。如果该仓库不是公开的,则需要将身份验证传递给Git命令。
然后,简单的方法是使用Kudu REST API将文件复制到Azure应用服务。
示例代码:
function Upload-FileToWebApp($kuduApiAuthorisationToken,$webAppName,$fileName,$localPath ){
$kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/app/resources/$fileName"
$result = Invoke-RestMethod -Uri $kuduApiUrl `
-Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
-Method PUT `
-InFile $localPath `
-ContentType "multipart/form-data"
}
此外,这里是您可以参考的ticket。
,是否还有其他任务/ powershell脚本/ ftp上传来复制3 发布中的部署任务之后的配置和设置文件 管道。
按照休的建议,您可以使用PS任务来调用Kudu api,以将文件上传到Azure App服务。这是我曾经回答的one similar issue。
但是我认为您也可以考虑另一个方向:
我们可以unzip the .zip which is to be deployed
=> add those files(web.config,log4net.config) to the extracted folder
=> archive the folder again=>deploy the newly archived zip file to azure app service
。