microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.5k stars 2.61k forks source link

Task stops working when moved to a Deployment Job #10604

Closed mdmoura closed 5 years ago

mdmoura commented 5 years ago

I have the following Azure-Pipelines.yml to build, test and deploy an ASP.NET Core Application.

trigger:
- master

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  version: '0.2.0'

jobs:
- job: Setup
  pool:
    vmImage: 'Ubuntu-16.04'
  steps:
  - task: DotNetCoreInstaller@0
    displayName: Install
    inputs:
      packageType: 'sdk'
      version: '2.2.105'
  - task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: '**/*.csproj'
      feedsToUse: 'config'
      nugetConfigPath: 'nuget.config'
  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: build
      projects: '**/*.csproj'
      arguments: '--configuration $(buildConfiguration)'
  - task: DotNetCoreCLI@2
    displayName: Test
    inputs:
      command: test
      projects: '**/*[Tt]est/*.csproj'
      arguments: '--configuration $(buildConfiguration)'
  - task: DotNetCoreCLI@2
    displayName: Publish
    inputs:
      command: publish
      publishWebProjects: false
      projects: '**/*.csproj'
      arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
      zipAfterPublish: true
  - task: PublishPipelineArtifact@0
    inputs:
      artifactName: drop 
      targetPath: '$(Build.ArtifactStagingDirectory)'
- deployment: Deploy
  dependsOn: Setup
  condition: succeeded()
  pool:
    vmImage: Ubuntu-16.04
  environment: production
  strategy:
    runOnce:
      deploy:
        steps:
        - task: DownloadPipelineArtifact@1
          inputs:
            artifactName: drop
        - task: AzureRmWebAppDeployment@4
          inputs:
            package: '$(Build.ArtifactStagingDirectory)/MyAppName.zip'
            azureSubscription: 'MyAzureSubscription'
            appType: 'Web App On Windows'
            webAppName: 'MyAppName'

The Setup job runs without a problem and at the end the artefacts are created.

I can see from the dropdown that I have a folder drop that contains file MyAppName.zip.

However when Deploy job runs, after Setup job, I get the error:

Error: No package found with specified pattern: /home/vsts/work/1/a/MyAppName.zip

Even the DownloadPipelineArtifact@1 runs fine. Only AzureRmWebAppDeployment@4 fails.

I am able to deploy it If I simply move the AzureRmWebAppDeployment@4 to the end of the first job:

jobs:
- job: Setup
  pool:
    vmImage: 'Ubuntu-16.04'
  steps:

  # Restore, Build, Test, ... Tasks 

  - task: PublishPipelineArtifact@0
    inputs:
      artifactName: drop 
      targetPath: '$(Build.ArtifactStagingDirectory)'

  - task: AzureRmWebAppDeployment@4
    inputs:
      package: '$(Build.ArtifactStagingDirectory)/MyAppName.zip'
      azureSubscription: 'MyAzureSubscription'
      appType: 'Web App On Windows'
      webAppName: 'MyAppName'

  # No more deployment Deploy job

Is it possible to make this work with 2 jobs?

Am I missing something or is this a bug?

kmkumaran commented 5 years ago

I believe the artifacts are downloaded (when you use DownloadPipelineArtifacts task) under a sub-folder called "drop".

In the AzureRmWebAppDeployment task, can you change the Package input as below and tell us if that works? Package: '$(build.artifactstagingdirectory)/*/MyAppName.zip'

chshrikh commented 5 years ago

@mdmoura can you please see if AzureRmWebAppDeployment task input "package" set to "'$(Pipeline.Workspace)/*/.zip'" helps you. ( Package: '$(Pipeline.Workspace)/*/.zip' ).

For you reference please see below sample YAML which builds and deploys the dot net web app to azure


trigger:
- master

variables:
  BuildConfiguration: 'release'
  BuildPlatform: 'any cpu'
  Solution: '**\*.sln'  
  AzureEndPointConnection: '<Your End point connection name>'
  AzureResourceGroupName: '<Resource Group Details>'
  AzureWebAppName: '<Web App Name>'

stages:
- stage: 'Build'
  displayName: "Build DotNet App"
  jobs:
  - job: 'BuildJob'
    pool:
      name: Hosted VS2017
      demands:
      - msbuild
      - visualstudio    

    steps:
    - task: NuGetInstaller@0
      displayName: 'NuGet restore'
      inputs:
        solution: '$(Solution)'

    - task: VSBuild@1
      displayName: 'Build solution'
      inputs:
        solution: '$(Solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
        platform: '$(BuildPlatform)'
        configuration: '$(BuildConfiguration)'

    - task: PublishSymbols@1
      displayName: 'Publish symbols path'
      inputs:
        SearchPattern: '**\bin\**\*.pdb'
      continueOnError: true    

    - task: CopyFiles@2
      displayName: 'Copy ARM templates'
      inputs:
        SourceFolder: ArmTemplates
        TargetFolder: '$(build.artifactstagingdirectory)'

    - upload: $(build.artifactstagingdirectory)        

- stage: Deployment
  displayName: "Deploy Dot Net App"
  dependsOn: Build
  jobs:
  - deployment: 'DeploymentJob'
    environment: ProdEnvironment-DotNetApp
    pool:
      name: Hosted VS2017
    strategy:
      runOnce:
        deploy:
          steps:               
          - task: AzureResourceGroupDeployment@2
            displayName: 'Azure Deployment:Create Azure App Service'
            inputs:
              azureSubscription: $(AzureEndPointConnection)
              resourceGroupName: '$(AzureResourceGroupName)'
              location: 'South Central US'
              csmFile: '$(Pipeline.Workspace)/**/windows-webapp-template.json'
              overrideParameters: '-webAppName "$(AzureWebAppName)" -hostingPlanName "$(AzureWebAppName)-plan" -appInsightsLocation "South Central US" -sku "S1 Standard"'
              steps:
          - task: AzureRmWebAppDeployment@4
            displayName: 'Deploy Azure App Service'
            inputs:
              azureSubscription: $(AzureEndPointConnection)
              WebAppName: '$(AzureWebAppName)'
              Package: '$(Pipeline.Workspace)/**/*.zip'
              WebAppUri: webAppUrl
              TakeAppOfflineFlag: true
              UseWebDeploy: true
              RenameFilesFlag: true
kmkumaran commented 5 years ago

@mdmoura - I hope the above suggestions worked for you. let us know if you need any further assistance.

mdmoura commented 5 years ago

@kmkumaran Thank you for the help ... Out of nothing it my code started working.

I used a tool to compare the code I posted here and the code that was working and the only differences were a few spaces or tabs ... Maybe it was a problem with YML format. Not sure ...

Thank you for the suggestions. Closing this issue.