0

My functions are under: /src/functions/

.NET Core functions named FunctionApp1 and FunctionApp2

I am trying to build both functions and deploy them to my function app.

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    projects: 'src/functions/**/*.csproj'
    arguments: '--output publish_output --configuration Release'

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: 'publish_output/'
    includeRootFolder: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Artifacts'
  inputs:
    artifactName: drop
    extractTars: false

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: myfunk'
  inputs:
    azureSubscription: '(sadfgghjkkk)'
    appType: functionApp
    appName: myfunk
    package: '$(System.ArtifactsDirectory)/*.zip'

The build and relase runs fine but I end up with only one function being present. How can I build every function I have in that directory and then publish them separately?

1 Answer 1

2

I would recommend you wrap this

- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    projects: 'src/functions/**/*.csproj'
    arguments: '--output publish_output --configuration Release'

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: 'publish_output/'
    includeRootFolder: false

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

- task: DownloadBuildArtifacts@0
  displayName: 'Download Build Artifacts'
  inputs:
    artifactName: drop
    extractTars: false

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: myfunk'
  inputs:
    azureSubscription: '(sadfgghjkkk)'
    appType: functionApp
    appName: myfunk
    package: '$(System.ArtifactsDirectory)/*.zip'

as a template and then simply reuse it a several times.

parameters:
- name: functionName
  type: string
  default: ' '

steps:
- script: echo ${{ parameters.functionName}}
- task: DotNetCoreCLI@2
  displayName: 'Build project'
  inputs:
    projects: 'src/functions/**/${{ parameters.functionName}}.csproj'
    arguments: '--output ${{ parameters.functionName}} --configuration Release'

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: '${{ parameters.functionName}}/'
    includeRootFolder: false
    archiveFile: '$(Build.ArtifactStagingDirectory)/${{ parameters.functionName}}-$(Build.BuildId).zip' 

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: ${{ parameters.functionName}}'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/${{ parameters.functionName}}-$(Build.BuildId).zip' 
    ArtifactName: '${{ parameters.functionName}}'

- task: AzureFunctionApp@1
  displayName: 'Azure Function App Deploy: myfunk'
  inputs:
    azureSubscription: '(sadfgghjkkk)'
    appType: functionApp
    appName: myfunk
    package: '$(Build.ArtifactStagingDirectory)/${{ parameters.functionName}}-$(Build.BuildId).zip'

and then

steps:
  - template: function-deploy.yml
    parameters:
      functionName: 'Func1'
  - template: function-deploy.yml
    parameters:
      functionName: 'Func2'

Note: I have no solution at hand to verify if there is not typo here.

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

4 Comments

I tried this approach but then the first deployed function would be just replaces by the next
Well, t can't use the same Azure Functions to host two apps. If you want to use only one Azure Functions please move all Functions from office app to another. Above code help you to by dry to deploy apps, but you can't host two apps in one resource.
thanks. That was the answer I was looking for.
This solution is very useful for my use case: deploy to multiple function apps from a single mother solution. Before this, I was having the opposite. Previously, I was deploying all the projects to the same function app (yes, it is possible and works, but there might be collisions on naming). Now I can deploy to multiple function apps thanks to this solution.

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.