Search code examples
azure-devopsazure-pipelines-release-pipeline

Duplicate a VS Web Deploy Publish (.pubxml) in Azure DevOps


I have an ASP.NET web app that I host via an Internet Service Provider (NOT via Azure). I manually deploy this in Visual Studio using a “Web Deploy” publish profile (a .pubxml file). See below.

ISSUE: I’d like to duplicate this deployment in Azure DevOps, rather than publish through Visual Studio. Despite days of effort, I have not figured out how to do it, nor find good examples.

Here is my Visual Studio Publish profile, which works just fine:

enter image description here

WHAT I'VE TRIED

  • Logged into Azure DevOps and went to Pipelines.
  • Create the Build pipeline, which builds the artifact fine, with no errors.
  • Create a Deployment Group:
    • Just gave it a name, and set “Type of target” to “Windows”
    • Note: This creates a PowerShell script. I’m not sure exactly what to do with this. I know the Visual Studio Web Deploy publish profile already works. Perhaps for AD to work, do I need to pass along this script to my ISP?
    • Note also: Under the ‘Targets’ tab, it just says “No targets.” This might be relevant info (see error in the last step).
  • Project Settings => Service connections => New service connection
    • Selected “Generic” (this seemed to make the most sense)
    • For “Server URL” entered the value from the Hosting, Server field from the publish profile above, along with username and pwd.
  • Pipelines => Releases => + New Release Pipeline
    • Select a template => “IIS website and SQL database deployment”
  • Add the Build Artifact from the first step
  • Edit “Stage 1”
    • Switched trigger to Manual
    • Remove the “IIS Web App Manage” step. This didn’t seem necessary since the web app is already working, and the VS publish deploys there fine.
    • Remove the “SQL Deployment” step. DB already created.
    • Left the “IIS Web App Deploy” step (mostly took default, just adding website name)
  • Deployed

After the deploy I get this:

error: “No machine found in given deployment group.”

QUESTIONS:

  1. Am I taking the correct approach here?
  2. Is there a way to just link an Azure DevOps release to my *.pubxml file, since I know they already work?

Solution

  • Regarding the error:

    error: “No machine found in given deployment group.”
    

    It's caused by the deployment group agent is not created, your release pipeline cannot found the agent to run.

    When you create the deployment group, you need to follow the guide, tick the option to include personal access token, and go to local machine, open powershell with admin permission, past the script to run. It will automatically register the deployment group agent for you.

    enter image description here

    Back to your query:

    You are in the correct direction, you can build artifact and then deploy it from release pipeline.

    But since you have *.pubxml file, you can also consider to directly publish it from Build task, details below:

    1. Check-in Your .pubxml File to source control repository under the Properties\PublishProfiles folder of your project.

    2. Setup a self-hosted agent with local machine on which can communicate and deploy to your website.

    3. Create a Build Pipeline, use above self-hosted agent. Use the Visual Studio Build task or MSBuild task. Include the following MSBuild arguments to use your .pubxml file:

    /p:DeployOnBuild=True;PublishProfile=<YourProfileName>
    

    Yaml task sample below, you can use same argument for classic UI task:

    - task: VSBuild@1
      inputs:
        solution: '$(solution)'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
        msbuildArgs: /p:DeployOnBuild=true;PublishProfile=Properties/PublishProfiles/DeploymentPackage.pubxml
    

    Here are some links which could be helpful:

    Windows Self-hosted agent setup

    deployment group setup

    Publish profiles