如何使用 Azure Devops 发布管道中的命令从 kudu 站点文件夹中删除文件

问题描述 投票:0回答:1

上下文:部署后,从 Kudu 站点控制台中的特定文件夹中删除文件。

我使用了前一个问题中给出的脚本语法,但这里的命令不同。

我尝试使用以下命令但没有成功:

del /Q "C:\home\site\wwwroot\License\*"
Remove-Item -Path 'C:\home\site\wwwroot\License\*' -force

错误

A positional parameter cannot be found that accepts argument 'C:\home\site\wwwroot\License\*'

总脚本

$WebApp = Get-AzWebApp -ResourceGroupName "AppServPlan-RG" -Name "testwebapp1013"
$publishingProfile = [xml](Get-AzWebAppPublishingProfile -WebApp $WebApp)
# Create Base64 authorization header
$Username = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userName").Node.Value
$Password = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userPWD").Node.Value
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password)))


$bodyToPOST = @{  
command = del /Q "C:\home\site\wwwroot\License\*" | XCOPY C:\home\License\*.* C:\home\site\wwwroot\License\
                 dir = "C:\home\"  
}  
# Splat all parameters together in $param  
$param = @{  
            # command REST API url  
            Uri = "https://testwebapp1013.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
azure azure-devops azure-web-app-service azure-pipelines azure-pipelines-release-pipeline
1个回答
0
投票

使用您的示例时我可以重现相同的问题:

要解决此问题,您可以使用以下示例:

$WebApp = Get-AzWebApp -ResourceGroupName "AppServPlan-RG" -Name "testwebapp1013"
$publishingProfile = [xml](Get-AzWebAppPublishingProfile -WebApp $WebApp)
# Create Base64 authorization header
$Username = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userName").Node.Value
$Password = (Select-Xml -Xml $PublishingProfile -XPath "//publishData/publishProfile[contains(@profileName,'Web Deploy')]/@userPWD").Node.Value
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password)))


$bodyToPOST = @{  
command = "del /Q C:\home\site\wwwroot\License\* | XCOPY C:\home\License\*.* C:\home\site\wwwroot\License\"
                 dir = "C:\home\"  
}  
# Splat all parameters together in $param  
$param = @{  
            # command REST API url  
            Uri = "https://testwebapp1013.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

整个命令需要添加双引号。

来自

command = del /Q "C:\home\site\wwwroot\License\*" | XCOPY C:\home\License\*.* C:\home\site\wwwroot\License\

command = "del /Q C:\home\site\wwwroot\License\* | XCOPY C:\home\License\*.* C:\home\site\wwwroot\License\"

结果样本:

© www.soinside.com 2019 - 2024. All rights reserved.