Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何使用八达通部署删除Azure应用程序服务网站上的文件夹_Powershell_Azure_Azure Web App Service_Octopus Deploy - Fatal编程技术网

Powershell 如何使用八达通部署删除Azure应用程序服务网站上的文件夹

Powershell 如何使用八达通部署删除Azure应用程序服务网站上的文件夹,powershell,azure,azure-web-app-service,octopus-deploy,Powershell,Azure,Azure Web App Service,Octopus Deploy,我正在使用TeamCity和Octopus Deploy(3.3.6版)为Sitecore网站设置一个自动部署项目 在使用“部署Azure Web应用”步骤部署到应用程序服务之前,我想删除该站点上的一个文件夹(/site/wwwroot/App\u Config/Include或D:\home\site\wwwroot\App\u Config\Include) 八达通中是否有内置的机制来实现这一点?我尝试过使用Powershell脚本,但它在服务器上运行,而不是在Azure上。部署时有没有办法

我正在使用TeamCity和Octopus Deploy(3.3.6版)为Sitecore网站设置一个自动部署项目

在使用“部署Azure Web应用”步骤部署到应用程序服务之前,我想删除该站点上的一个文件夹(/site/wwwroot/App\u Config/Include或D:\home\site\wwwroot\App\u Config\Include)

八达通中是否有内置的机制来实现这一点?我尝试过使用Powershell脚本,但它在服务器上运行,而不是在Azure上。部署时有没有办法在Azure上运行Powershell脚本? 或者我可以使用“运行Azure Powershell脚本”在应用程序服务网站上进行文件操作,而无需进行身份验证(因为八达通正在进行身份验证)

或者,是否有其他/更好的解决方案来解决此问题,而无需将凭据保存在生成服务器上的文件中

如果可能的话,我宁愿不使用FTP。我会这样做:

  • 在Azure中创建按需webjob,并上载powershell脚本,该脚本可将文件夹清理到您的Webapp中。尝试保持此ps脚本简单,使用基本cmdlet命令,并非所有ps模块都将在azure中运行。 如何:

  • 您仍然需要您的teamcity或八达通来运行powershell线路来启动webjob。这样,工作负载就不再在octopus服务器上了,但您仍然需要对powershell行执行相同的azure身份验证过程。 如何:

  • 八达通中的“运行Azure Powershell脚本”可帮助您加载Azure Powershell模块并执行Azure订阅技巧,因此您无需在脚本中包含库或重新验证。它仍然在本地运行,但步骤2非常适合这一点


    希望这能对你有所帮助。

    最后我还是决定使用FTP。尽管我非常喜欢Kai Zhao的建议,但我更愿意将所有与自动部署相关的内容都保留在部署服务器上,而不必在不同的位置放置和维护脚本

    我使用了以下Powershell FTP客户端模块,并将其安装在构建服务器上:

    我使用这个脚本来执行实际的删除操作,并将其作为Octopus中的一个步骤运行:

    $AzureAppService是八达通中的一个变量,其变化取决于 环境


    有人知道如何从PowerShell AzureRM.Resources模块创建WebJobs吗?
    Import-Module PSFTP 
    $username = $AzureAppService
    $password = ConvertTo-SecureString "************" -AsPlainText -Force
    $cred = new-object -typename System.Management.Automation.PSCredential `
             -argumentlist $username, $password
    $ftpserver = "***url_to_your_ftp_server**"
    $folderToDelete = "/site/wwwroot/App_Config/Include"
    Set-FTPConnection -Credentials $cred -Server $ftpserver -Session MyFTPSession -UsePassive 
    $Session = Get-FTPConnection -Session MyFTPSession
    Try
    {
        Remove-FTPItem -Session $Session -Path $folderToDelete -Recurse 
    }
    Catch
    {
        Write-Warning "There was an error while trying to remove the folder:"
        Write-Warning $_.Exception.Message
        Write-Warning $_.Exception.ItemName
    }