skip to Main Content

I am trying to create a Devops Pipeline to deploy to a Python Azure Function App. Using Vs code I can successfully deploy to the function app and everything works 100%. I had to add 2 app settings mentioned here (https://github.com/anthonychu/20220303-python-func-playwright) to get it working.

Next steps was to create a Pipeline in Azure Devops. I tried using the classic editor and the YAML creator but I just cant get Playwright to install. I keep getting the error:
Looks like Playwright was just installed or updated. Please run the following command to download new browsers: playwright install <3 Playwright Team.

Anyone here managed to get a Devops pipeline to deploy to a Python Azure Function App V2 that includes Playwright to work yet?

Basically I need to figure out how to run playwright install chromium as a post build task. I tried adding a POST_BUILD_COMMAND app setting but it doesn’t seem to run when I deploy using the Pipeline, its does however run when deploying using VS Code

My current YAML:

pool:
  vmImage: ubuntu-latest

steps:
- task: UsePythonVersion@0
  displayName: "Set Python version to 3.10"
  inputs:
    versionSpec: '3.10'
    architecture: 'x64'

- bash: |
    if [ -f extensions.csproj ]
    then
        dotnet build extensions.csproj --output ./bin
    fi
    pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt

- bash: |
    sudo mkdir -p /home/site/wwwroot
    PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot
    python -m pip install playwright
    PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot /opt/hostedtoolcache/Python/3.10.13/x64/bin/python3.10 -m playwright install chromium
  displayName: 'Install Playwright'


- task: ArchiveFiles@2
  displayName: "Archive files"
  inputs:
    rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
    includeRootFolder: false
    archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
    artifactName: 'drop'

2

Answers


    1. Create a yaml pipeline from the template:
      enter image description here
    2. Use the following scripts to install chromium in the yaml pipeline.
        - bash: |
            pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
            cd ./.python_packages/lib/site-packages
            python -m playwright install chromium 
          workingDirectory: $(workingDirectory)
          displayName: 'Install application dependencies'
          env:
            PLAYWRIGHT_BROWSERS_PATH: $(workingDirectory)
    
    1. Add an app setting PLAYWRIGHT_BROWSERS_PATH=/home/site/wwwroot in the function app.
      enter image description here

    2. Then the function works as shown below.
      enter image description here

    Login or Signup to reply.
  1. I am running a jenkins piple line and I use the Playwright image instead. I am quoting the Playwright documentation. I am using the Jammy image myself in my pipeline

    docker pull mcr.microsoft.com/playwright:v1.41.1-jammy
    

    Have you tried that? That could be a potential solution and you won’t have to hunt for the right version of chromium and install it. This comes preinstalled with Playwright browsers.

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