Azure devops 将其他文件重命名或部署到Azure Web App

Azure devops 将其他文件重命名或部署到Azure Web App,azure-devops,azure-pipelines,azure-web-app-service,azure-pipelines-release-pipeline,Azure Devops,Azure Pipelines,Azure Web App Service,Azure Pipelines Release Pipeline,作为Azure DevOps发布管道的一部分,我希望在“部署Azure应用程序服务”任务完成后,将一些.config文件重命名为.config.disabled 我试图添加一个额外的“部署Azure应用程序服务”任务,但这似乎覆盖了上一个任务,只在wwwroot中保留了.config.disabled文件 是否有其他方法(FTP上载任务除外)可用于在Azure web应用程序中重命名/部署文件子集?如果您不想使用FTP,您可能会成功尝试使用支持Azure web应用程序的 要查看Kudu服务,请

作为Azure DevOps发布管道的一部分,我希望在“部署Azure应用程序服务”任务完成后,将一些
.config
文件重命名为
.config.disabled

我试图添加一个额外的“部署Azure应用程序服务”任务,但这似乎覆盖了上一个任务,只在wwwroot中保留了
.config.disabled
文件


是否有其他方法(FTP上载任务除外)可用于在Azure web应用程序中重命名/部署文件子集?

如果您不想使用FTP,您可能会成功尝试使用支持Azure web应用程序的

要查看Kudu服务,请导航至https://.scm.azurewebsites.net

通过身份验证后,您会发现有一种方法可以浏览文件、查看正在运行的进程,还有一个交互式控制台,允许您针对文件系统运行基本的DOS或PowerShell命令

交互式控制台很棒,但要使其自动化,您可以使用RESTAPI对文件系统发出命令

这里有几个例子。在PowerShell中:

# authenticate with Azure
Login-AzureRmAccount
$resoureGroupName = "your-web-app-name"
$websiteName = "your-resource-group-name"

$env = @{
     command= 'Set COMPUTERNAME'
     dir= 'site'
}
$json = $env | ConvertTo-Json

$env2 = @{
     command= 'copy filename.config file.config.notused'
     dir= 'site\wwwroot'
}
$json2 = $env2 | ConvertTo-Json

$env3 = @{
     command= 'delete filename.config'
     dir= 'site\wwwroot'
}
$json3 = $env3 | ConvertTo-Json

# setup auth header
$website = Get-AzureWebsite -Name $websiteName
$username = $website.PublishingUsername
$password = $website.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

$apiBaseUrl = "https://$($website.Name).scm.azurewebsites.net/api"
[System.Uri]$Uri = $apiBaseUrl

# get all the vms in the web-app
$instances = Get-AzureRmResource -ResourceGroupName $resoureGroupName `
                                -ResourceType Microsoft.Web/sites/instances `
                                -ResourceName $websiteName `
                                -ApiVersion 2018-02-01

#loop through instances
foreach($instance in $instances)
{
    $instanceName = $instance.Name
    Write-Host "`tVM Instance ID `t`t: " $instanceName

    #Now execute 'SET COMPUTER' cmd
    $cookie= New-Object System.Net.Cookie
    $cookie.Name = "ARRAffinity"
    $cookie.Value = $instanceName
    $Cookie.Domain = $uri.DnsSafeHost
    $session=New-Object Microsoft.Powershell.Commands.WebRequestSession
    $session.Cookies.add($cookie)
     $response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
                                -Headers @{Authorization=("Basic {0}" `
                                -f $base64AuthInfo)} `
                                -Method Post -Body $json `
                                -ContentType 'application/json' `
                                -WebSession $session
    Write-Host "`tVM Instance Name `t: " $response

    # perform copy file
    $response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
                               -Headers @{Authorization=("Basic {0}" `
                               -f $base64AuthInfo)} `
                               -Method Post -Body $json2 `
                               -ContentType 'application/json' `
                               -WebSession $session
    Write-Host "`tCopy file result `t: " $response

    # perform delete file
    $response = Invoke-RestMethod -Uri "$apiBaseUrl/command" `
                               -Headers @{Authorization=("Basic {0}" `
                               -f $base64AuthInfo)} `
                               -Method Post -Body $json3 `
                               -ContentType 'application/json' `
                               -WebSession $session
    Write-Host "`tCopy file result `t: " $response
 }    

文件系统支持基本命令,如“复制”和“删除”,以便您可以轻松重命名文件。

如果您可以在之前进行修改,为什么要在之后进行修改?我需要运行一个脚本,该脚本要求站点联机,当脚本运行后,我需要禁用该脚本再次运行的机会。脚本执行一些数据库同步,为了避免脚本意外运行,我想在运行完脚本后立即禁用它(通过禁用.config文件),谢谢!我注意到顶部的“登录AzurerAccount”-这在Azure DevOps中如何工作?我能通过一些证书吗?甚至更好。使用Azure PowerShell任务建立与Azure订阅的服务连接。PowerShell任务将在该上下文下执行。而且,由于您是新手:如果这回答了您的问题,您是否介意接受答案(并投票表决)?