2

I have a Azure function that is targeting .net framework 4.8

It's working fine when I deploy it thorough visual studio but I am trying to create a azure-pipeline.yml file for deployment. But it actually put the root level files in the artifact folder and not the ones that visual studio puts in the publish folder.

I can't find any good help for .net framework.

Here is my yaml file:

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: ArchiveFiles@2
      displayName: 'Archive Function'
      #condition: and(succeeded(), eq(variables.isDeployableBranch, true))
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)/src/FunctionApp'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/FunctionApp.zip'
        replaceExistingArchive: true

    - 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: 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 something is wrong before Archive stage. For other regular mvc apps targeting .net framework, the same pipeline works fine but for the azure function. Am I missing something?

1 Answer 1

1

This is my function's structure:

enter image description here

And the below YAML works fine:

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.4.1'
  inputs:
    versionSpec: 4.4.1

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: ArchiveFiles@2
  displayName: 'Archive $(System.DefaultWorkingDirectory)\FrameworkFunction\bin\release\net48\*'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)\FrameworkFunction\bin\release\net48\*'

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: testbowman0613'
  inputs:
    azureSubscription: 'testbowman_in_AAD'
    appType: functionApp
    appName: testbowman0613
    package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'

enter image description here

The key is the path must be correct, otherwise, it will not work.

Sign up to request clarification or add additional context in comments.

Comments

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.