Deploying a Python Azure Function in Azure DevOps Error: Directory ‘D:\a\1\a’ is empty. Nothing will be added to build artifact ‘drop’.

Author by Nathan Lasnoski

I was having challenge with deploying an Azure Function through Azure DevOps where the default channel was failing to capture the output of the build and deploy it to the target. I wanted to post a template for this, as there were a lot of people trying to solve the same problem, but no clear answer for this specific use case.

# Python package
# Create and test a Python package on multiple Python versions.
# Add steps that analyze code, save the dist with the build record, publish to a PyPI-compatible index, and more:
#    pip install -r requirements.txt

- master

  vmImage: 'ubuntu-latest'
      python.version: '3.7'

- task: UsePythonVersion@0
    versionSpec: '$(python.version)'
  displayName: 'Use Python $(python.version)'

- script: |
    python -m pip install --upgrade pip

    pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
  displayName: 'Install dependencies'

- task: CopyFiles@2
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '**'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: ArchiveFiles@2
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true

- task: AzureFunctionApp@1
    azureSubscription: 'Customer-Project-Production (11111111-1111-1111-1111-111111111111)'
    appType: 'functionAppLinux'
    appName: 'Customer-ImageData-Prod-01'
    package: '$(Build.ArtifactStagingDirectory)/**/*.zip'

The main mis-match I didn’t have was the correct directory being copied and then sent to the AzureFunctionApp@1

Good luck!

Nathan Lasnoski


Nathan Lasnoski

Chief Technology Officer