2016-04-14 47 views
1

我正在使用TeamCity和Octopus Deploy(v.3.3.6)爲Sitecore網站設置自動部署項目。如何使用Octopus Deploy刪除Azure App Service網站上的文件夾

在使用「部署Azure Web App」步驟部署到App Service之前,我想刪除該站點上的一個文件夾(/ site/wwwroot/App_Config/Include或D:\ home \ site \ wwwroot \ APP_CONFIG \包含)。

八達通是否有內置機制來做到這一點?我嘗試過使用Powershell腳本,但是在服務器上運行,而不是在Azure上運行。有沒有辦法在部署時在Azure上運行Powershell腳本? 或者我可以使用「運行Azure Powershell腳本」在App Service網站上進行文件操作,而無需進行身份驗證(因爲Octopus正在進行身份驗證)?

還有沒有其他的/更好的解決方案來解決這個問題,而不必在Build Server的文件中保存憑據?

如果可能的話,我寧願不使用FTP。

回答

1

我這樣做:

  1. 創建點播webjob在Azure和上傳PowerShell腳本,可以清理文件夾,你的web應用。儘量保持這個ps腳本簡單,使用base cmdlet命令,並不是所有的ps模塊都可以在azure中運行。 如何:https://blogs.msdn.microsoft.com/nicktrog/2014/01/22/running-powershell-web-jobs-on-azure-websites/

  2. 您仍然需要您的teamcity或章魚運行powershell行來啓動webjob。有了這個,工作負載不再在八達通服務器上了,但你仍然需要對powershell線路進行相同的天藍色認證過程。 如何:http://www.nullfactory.net/2015/05/start-azure-webjobs-on-demand/

「運行一個Azure的PowerShell腳本」章魚可以幫助您加載在Azure Powershell的模塊,並做了Azure的認購招,所以你並不需要包括腳本或重中的庫-認證。它仍然在本地運行,但第2步很適合。

希望這可以幫助你。

+0

任何人對如何創建一個從PowerShell的AzureRM.Resources'模塊WebJobs什麼想法? – SOReader

0

最後我決定使用FTP。儘管我非常喜歡Kai Zhao的建議,但我更願意在部署服務器上保留與自動部署相關的所有內容,而不必在不同位置放置和維護腳本。

我用下面的PowerShell的FTP客戶端模塊,並安裝了我們構建服務器上:https://gallery.technet.microsoft.com/scriptcenter/PowerShell-FTP-Client-db6fe0cb

而且我用這個腳本做實際刪除,然後運行它作爲八達通步:

$ AzureAppService是Octopus中的一個變量,其變化取決於 環境。

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 
} 
相關問題