Home > Software engineering >  How to publish an azure function to an Azure Linux Function in Active Directory from a Devops Pipeli
How to publish an azure function to an Azure Linux Function in Active Directory from a Devops Pipeli

Time:08-07

I am trying to create a Devops Pipeline to publish an Azure Function Project in a Linux Function App. This is the pipeline I made so far:

pool:
  vmImage: ubuntu-latest

steps:
- task: UseDotNet@2
  inputs:
    version: '6.0.x'

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: |
      **/*.csproj     

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: |
      **/*.csproj      
    arguments: '--configuration Release'
    
- task: ArchiveFiles@2
  displayName: 'Archive Test'
  inputs:
    archiveType: 'zip'
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)/Test.Company.API/bin/Release/net6.0/'
    archiveFile: '$(System.DefaultWorkingDirectory)/Test.Company.API/bin/Release/net6.0/$(Build.BuildId).zip'

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy - Test Company'
  inputs:
    azureSubscription: 'Test_Sub'
    appType: 'functionAppLinux'
    appName: 'test-company'
    package: '$(System.DefaultWorkingDirectory)/**/*.zip'
    runtimeStack: 'DOTNET|6.0'

And this is what I see in the last task:

Got service connection details for Azure App Service:'test-company'
Trying to update App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"https://test.blob.core.windows.net/azure-pipelines-deploy/package_1659618746343.zip?***"}
Updated App Service Application settings.
Updated WEBSITE_RUN_FROM_PACKAGE Application setting to https://test.blob.core.windows.net/azure-pipelines-deploy/package_1659618746623.zip?***
Syncing triggers for function app
Sync triggers for function app completed successfully
Successfully added release annotation to the Application Insight : test_insights
App Service Application URL: https://test-company.azurewebsites.net
Finishing: Azure Function App Deploy - Test Company

However when I get to the Azure Function in the Azure Directory the functions are not deployed, even though the DevOps pipeline was successful.

CodePudding user response:

Ok I found the problem.

I had to add this line under ArchiveFiles@2

includeRootFolder: false

The problem was that it was creating a zip with the root folder inside so the host.json was inside net6.0 and not inside the root.

I was able to understand the issue by view the zip files inside the storage.

Another change that I made was to publish the app instead of building the app

Here are the final tasks:

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    projects: '$(System.DefaultWorkingDirectory)/Test.API/Test.API.csproj'
    command: 'publish'
    arguments: '--configuration Release --output publish'
    publishWebProjects: false
    zipAfterPublish: false
    modifyOutputPath: false
    
- task: ArchiveFiles@2
  displayName: 'Archive Test'
  inputs:
    includeRootFolder: false
    replaceExistingArchive: true
    archiveType: 'zip'
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish'
    archiveFile: '$(System.DefaultWorkingDirectory)/Test.API/bin/Release/net6.0/$(Build.BuildId).zip'
    
- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy - Test'
  inputs:
    azureSubscription: 'Test_Sub'
    appType: 'functionAppLinux'
    appName: 'test'
    package: '$(System.DefaultWorkingDirectory)/**/*.zip'
    runtimeStack: 'DOTNET|6.0'
  • Related