skip to Main Content

I am moving from a python function app to a powershell function app. I have a build and release pipeline for this. The following code below is the build for a python function app. how would i do this for a powershell function app.

#------------------------------------------------------------------------------------
#parametrise service connection detials 
#------------------------------------------------------------------------------------
variables:
  azureServiceConnection: 'my-service-connection'
# -------------------------------------------------------------------------------------
# What VM OS will run this pipeline
# -------------------------------------------------------------------------------------
pool:
  vmImage: 'ubuntu-latest'
# -------------------------------------------------------------------------------------
# A Build pipeline is definined in a hierarchy of Stages > Jobs > Steps,
# This example has a single stage and job and therefore those don't need to be listed
# -------------------------------------------------------------------------------------
steps:
- bash: |
   if [ -f extensions.csproj ]
   then
       dotnet build extensions.csproj --output ./bin
   fi
  displayName: 'Build extensions'

- task: UsePythonVersion@0
  displayName: Use Python 3.8
  inputs:
    versionSpec: '3.8'
    addToPath: true 
# -------------------------------------------------------------------------------------
#Run Pip installer for any prerequisite libraries
# -------------------------------------------------------------------------------------
- bash: 'pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt'
  displayName: 'Install Application Dependencies'
# -------------------------------------------------------------------------------------
#Archieve all files
# -------------------------------------------------------------------------------------
- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
# -------------------------------------------------------------------------------------
#drop files copied to artifact staging directory
# -------------------------------------------------------------------------------------
- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

2

Answers


  1. For a powershell function app, you can simply deploy using the AzureFunctionApp@2 task. See docs here.

    Here is my example pipeline that I use to deploy to a powershell function app, there is no release pipeline necessary.

    steps:
      - checkout: self
    
      - task: AzureFunctionApp@2
        inputs:
          azureSubscription: $(subscription)
          appName: ${{ parameters.FunctionApp }}
          resourceGroupName: ${{ parameters.ResourceGroup }}
          slotName: $(slot name)
          package: "$(System.DefaultWorkingDirectory)/function-apps/${{ parameters.FunctionApp }}/"
          appSettings: -WEBSITE_TIME_ZONE "New Zealand Standard Time"
          deploymentMethod: auto
    

    For me, the package input paths directly to my function app folder that looks like this:

    enter image description here

    If you would prefer to have this as a release pipeline, you should also be able to find that same task in the release pipeline, and then you can include your repostiroy as an artifact, and set up a trigger to deploy when code is merged to your master/main branch.

    enter image description here

    Login or Signup to reply.
  2. Based on your requirement, you need to deploy the files to the PowerShell Azure Function.

    When deploying the Powershell function app, we can directly deploy the Powershell file without compiling the .ps1 file.

    Since you need to include the build and release pipelines, you can directly package the relevant powershell files in the build pipeline and then use them for release pipeline deployment.

    You can use the following Yaml sample in Build Pipeline to package your powershell project.

    variables:
      # Azure Resource Manager connection created during pipeline creation
      azureSubscription: 'Azureserviceconnectionname'
    
    
    stages:
    - stage: Build
      displayName: Build stage
    
      jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: windows-2019
    
        steps:
        - powershell: |
            if (Test-Path "extensions.csproj") {
                dotnet build extensions.csproj --output ./$(System.DefaultWorkingDirectory)/bin
            }
          displayName: 'Build extensions'
    
        - task: ArchiveFiles@2
          displayName: 'Archive files'
          inputs:
            rootFolderOrFile: $(System.DefaultWorkingDirectory)
            includeRootFolder: false
            archiveType: zip
            archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
            replaceExistingArchive: true
    
        - publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
          artifact: drop
    

    Release Pipeline: The configuration is same as the steps to deploy python function app.

    enter image description here

    In order to create a Pipeline workflow more conveniently, you can also directly use the Yaml Template in Pipelines -> New Pipelines -> Azure Repos Git(YAML) -> select repo -> find template: PowerShell Function App to Windows on Azure at configure step.

    enter image description here

    It can automatically help you create a complete build and deployment process.

    For more detailed info, you can refer to this blog: Integrate your PowerShell Azure Function with Azure DevOps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search