简体   繁体   中英

Azure DevOps Pipeline to non-Azure site via FTP App_Offline

  1. I'm deploying from an Azure DevOps pipeline to a non-Azure website I have only ftp access to.
  2. The ASP.NET Core 5.0 site is running, so I need to drop an App_Offline.html in there, do my FTP deploy, then get rid of the App_Offline again.

Without the App_Offline you can't overwrite the.dll bits of the active site, and I can't get it to delete them either, so I definitely need to take the site offline. I do not want to do that manually as it makes the pipeline less useful.

I can't be the only/ first person to need to do this - does anyone have some YAML which will do that specific job please?

You can use "EnableMSDeployAppOffline" feature to set your app offline before deployment by following the instruction here: Web publishing updates for app offline and usechecksum .

If it does not work, you can also add a PowerShell task to run script as following to stop the app, deploy and then restart the app:

    param($websiteName, $packOutput)

    $website = Get-AzureWebsite -Name $websiteName

    # get the scm url to use with MSDeploy.  By default this will be the second in the array
    $msdeployurl = $website.EnabledHostNames[1]


    $publishProperties = @{'WebPublishMethod'='MSDeploy';
                            'MSDeployServiceUrl'=$msdeployurl;
                            'DeployIisAppPath'=$website.Name;
                            'Username'=$website.PublishingUsername;
                            'Password'=$website.PublishingPassword}

    Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName

See thread: VSTS - Take app offline before deployment for more details.

I got the upload to work...

Step 1: Add an App_Offline.htm file to the repo

Step 2: add an initial FTP step to take the site offline before the ftp upload of the site itself. Like this (settings are similar to those used for the actual deployment ftp, except for the filePatterns):

- task: FtpUpload@2
  inputs:
    credentialsOption: 'inputs'
    serverUrl: 'ftp://ftpx.ftptothesite.com' # 3rd party hoster site address
    username: '$(ftpUsername)'
    password: '$(ftpPassword)'
    rootDirectory:  '$(Build.ArtifactStagingDirectory)/s'
    filePatterns: 'app_offline.htm'
    remoteDirectory: '/web/content/'
    preservePaths: true
    trustSSL: true
  displayName: 'Take site offline'

That makes the upload work, but leaves the remote site offline (because there's an app_offline.htm in the root there).

Step3: Delete app_offline.htm Note that the FTP task has a "customCmds" parameter which MS describe as:

Optional FTP Commands that will be sent to the remote FTP server upon connection

My italics. The custom commands are run before the FTP task they are defined in, not after. Hence I needed one more FTP upload task, of something benign, but with a DELE /web/content/app_offline.htm as the last command. Note that the full path is needed, presumably as this runs before the remoteDirectory is set up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM