0

I have multiple .net mvc apps and 1 .net azure function app in our solution. I have a azure-pipeline.yml file for deployment. Mvc apps goes to app services and Function app goes to azure function.

Now when I run the pipeline on azure devops, it deploys webapps to respective app service but it fails to deploy the azure function with the error:

##[error]Error: No package found with specified pattern: D:\a\1\a**\FunctionApp.zip
Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job. Finishing: AzureFunctionApp

But I can see FunctionApp.zip in build artifacts.

Here is my yml:

trigger:
- master
- feature/*
- hotfix/*

pool:
  vmImage: 'windows-2019'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  isMaster: $[eq(variables['Build.SourceBranch'], 'refs/heads/master')]
  isDeployableBranch: $[eq(variables.isMaster, true)]

stages:
- stage: Build
  displayName: Build and Test Package
  jobs:
  - job: Build_Test_Publish
    displayName: Build_Test_Publish
    steps:
    - task: NuGetToolInstaller@1

    - task: VisualStudioTestPlatformInstaller@1
      displayName: 'Install Visual Studio Test Platform'
      inputs:
        packageFeedSelector: 'nugetOrg'
        versionSelector: 'latestStable'

    - task: NuGetCommand@2
      displayName: 'Restore NuGet packages'
      inputs:
        command: 'restore'
        restoreSolution: '$(solution)'
        feedsToUse: 'config'
        nugetConfigPath: './'
        externalFeedCredentials: 'Telerik NuGet'

    - task: VSBuild@1
      displayName: 'Build Solution'
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=$(isDeployableBranch) /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: VSTest@2
      displayName: 'Run Unit Tests'
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'

    - task: PublishBuildArtifacts@1
      condition: and(succeeded(), eq(variables.isDeployableBranch, true))
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'


- stage: Deploy
  displayName: Deploy
  condition: and(succeeded(), eq(variables.isDeployableBranch, true))
  jobs:
  - deployment: DeployWebApp1
    displayName: Deploy Web App 1
    environment: 'PROD'
    strategy:
      runOnce:
        deploy:
          steps:
          - checkout: none
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              downloadType: 'single'
              artifactName: 'drop'
              downloadPath: '$(System.ArtifactsDirectory)'
              
          - task: AzureRmWebAppDeployment@4
            inputs:
              ConnectionType: 'AzureRM'
              azureSubscription: 'MyResourcegroup'
              appType: 'webApp'
              WebAppName: 'webapp1'
              packageForLinux: '$(System.ArtifactsDirectory)/**/WebApp1.zip'

  - deployment: DeployWebApp2
    displayName: Deploy Web App 2
    environment: 'PROD'
    strategy:
      runOnce:
        deploy:
          steps:
          - checkout: none
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              downloadType: 'single'
              artifactName: 'drop'
              downloadPath: '$(System.ArtifactsDirectory)'
              
          - task: AzureRmWebAppDeployment@4
            inputs:
              ConnectionType: 'AzureRM'
              azureSubscription: 'MyResourceGroup'
              appType: 'webApp'
              WebAppName: 'webapp2-motionkinetic'
              packageForLinux: '$(System.ArtifactsDirectory)/**/WebApp2.zip'

  
  - deployment: DeployFunction
    displayName: Deploy Function
    environment: 'PROD'
    strategy:
      runOnce:
        deploy:
          steps:
          - checkout: none
          - task: DownloadBuildArtifacts@0
            inputs:
              buildType: 'current'
              downloadType: 'single'
              artifactName: 'drop'
              downloadPath: '$(System.ArtifactsDirectory)'

          - task: AzureFunctionApp@1 
            inputs:
               azureSubscription: 'MyResourceGroup'
               appType: functionApp
               appName: 'MyFunction'
               package: '$(System.ArtifactsDirectory)/**/FunctionApp.zip'

I think the issue is in the yml file itself. What am I doing wrong?

1
  • 1
    Did you add an inline script step to check if the expected file exists where you think it exists? Commented Jun 7, 2022 at 18:03

1 Answer 1

1

Update:

trigger:
- main

pool:
  vmImage: 'windows-latest'


stages:
  - stage: C
    displayName: C
    jobs:
    - job: xxx
      displayName: xxxOfC
      steps:
      - task: VSBuild@1
        inputs:
          solution: '**\*.sln'
      - task: CmdLine@2
        inputs:
          script: |
            mkdir AF
            mkdir MVC1
            mkdir MVC2
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/FunctionAppAndMVC/bin/Debug/netcoreapp3.1'
          Contents: '**'
          TargetFolder: '$(System.DefaultWorkingDirectory)/AF'
        displayName: Copy Files to AF
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/MVC1/bin/Debug/netcoreapp3.1'
          Contents: '**'
          TargetFolder: '$(System.DefaultWorkingDirectory)/MVC1'
        displayName: Copy Files to MVC1(1)
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/MVC1/wwwroot'
          Contents: '**'
          TargetFolder: '$(System.DefaultWorkingDirectory)/MVC1'
        displayName: Copy Files to MVC1(2)
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/MVC2/bin/Debug/netcoreapp3.1'
          Contents: '**'
          TargetFolder: '$(System.DefaultWorkingDirectory)/MVC2'
        displayName: Copy Files to MVC2(1)
      - task: CopyFiles@2
        inputs:
          SourceFolder: '$(System.DefaultWorkingDirectory)/MVC2/wwwroot'
          Contents: '**'
          TargetFolder: '$(System.DefaultWorkingDirectory)/MVC2'
        displayName: Copy Files to MVC2(2)
      
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: '$(System.DefaultWorkingDirectory)/AF'
          includeRootFolder: true
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
          replaceExistingArchive: true
        displayName: Archive Azure Function Files
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: '$(System.DefaultWorkingDirectory)/MVC1'
          includeRootFolder: true
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/MVC1.zip'
          replaceExistingArchive: true
        displayName: Archive MVC1 Files
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: '$(System.DefaultWorkingDirectory)/MVC2'
          includeRootFolder: true
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/MVC2.zip'
          replaceExistingArchive: true
        displayName: Archive MVC2 Files
      
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'drop'
          publishLocation: 'Container'
        displayName: Publish Artifact
  - stage: D
    displayName: Deploy
    jobs:
    - job: xxx
      displayName: xxxOfD
      steps:
      - task: DownloadBuildArtifacts@1
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: 'drop'
          downloadPath: '$(System.ArtifactsDirectory)'
      - task: AzureFunctionApp@1
        inputs:
          azureSubscription: 'testbowman_in_AAD'
          appType: 'functionApp'
          appName: 'testbowman'
          package: '$(System.ArtifactsDirectory)/drop/AF.zip'
          deploymentMethod: 'auto'
      - task: AzureWebApp@1
        inputs:
          azureSubscription: 'xxx'
          appType: 'webApp'
          appName: 'xxx'
          package: '$(System.ArtifactsDirectory)/drop/MVC1.zip'
          deploymentMethod: 'auto'
      - task: AzureWebApp@1
        inputs:
          azureSubscription: 'xxx'
          appType: 'webApp'
          appName: 'xxx'
          package: '$(System.ArtifactsDirectory)/drop/MVC2.zip'
          deploymentMethod: 'auto'

Original Answer:

I don't see the FunctionApp.zip before the deploy stage.

Seems no one archived files as 'FunctionApp.zip'(From your YAML I can't see it).

Below YAML will work:

trigger:
- main

pool:
  vmImage: 'windows-latest'

stages:
  - stage: C
    displayName: C
    jobs:
    - job: xxx
      displayName: xxxOfC
      steps:
      - task: ArchiveFiles@2
        inputs:
          rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
          includeRootFolder: true
          archiveType: 'zip'
          archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
          replaceExistingArchive: true
      - task: PublishBuildArtifacts@1
        inputs:
          PathtoPublish: '$(Build.ArtifactStagingDirectory)'
          ArtifactName: 'drop'
          publishLocation: 'Container'
  - stage: D
    displayName: Deploy
    jobs:
    - job: xxx
      displayName: xxxOfD
      steps:
      - task: DownloadBuildArtifacts@1
        inputs:
          buildType: 'current'
          downloadType: 'single'
          artifactName: 'drop'
          downloadPath: '$(System.ArtifactsDirectory)'
      - task: AzureFunctionApp@1
        inputs:
          azureSubscription: 'testbowman_in_AAD'
          appType: 'functionApp'
          appName: 'testbowman'
          package: '$(System.ArtifactsDirectory)/**/*.zip'
          deploymentMethod: 'auto'
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the answer, had to do small tweaks in your answer but indeed that was the problem.
So I thought that the tweaks I made actually worked but they haven't. So actually I have two other mvc projects (part of the same solution) as well that I want to deploy via same yml. The archive step actually archive whole solution and deploy all projects to each app service and azure function. How can I fix that?
@Ask The key is 'path', the deploy task always based on some specific path, If you need a sample, please let me know.
that would be really helpful if you can share the sample
@Ask I have update the answer, just to provide an idea for your reference.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.