pythonazureazure-devopsazure-web-app-serviceazure-blob-storage

##[error]Error: Error: Failed to deploy web package to App Service. Conflict (CODE: 409)


I've been trying to deploy my FastAPI application on Azure DevOps for the past two days. It was working perfectly before, but now it's not working even though I haven't made any changes to the pipeline.

My Pipeline is:

trigger:
- main

variables:
  azureServiceConnectionId: service_connectionID
  webAppName: appname
  vmImageName: 'image'
  environmentName: 'env'
  projectRoot: $(System.DefaultWorkingDirectory)
  pythonVersion: '3.11'

stages:
- stage: Build
  displayName: Build stage
  jobs:
  - job: BuildJob
    pool:
      vmImage: $(vmImageName)
    steps:
    # Set up Python environment
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(pythonVersion)'
      displayName: 'Use Python $(pythonVersion)'

    # Install dependencies
    - script: |
        python -m venv antenv
        source antenv/bin/activate
        python -m pip install --upgrade pip
        pip install setuptools wheel
        pip install -r requirements.txt
      workingDirectory: $(projectRoot)
      displayName: 'Install requirements'
      
    # Create deployment package
    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(projectRoot)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    # Publish build artifacts
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    environment: $(environmentName)
    pool:
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:
          # Deploy the web app
          - task: AzureWebApp@1
            displayName: 'Deploy Azure Web App'
            inputs:
              azureSubscription: $(azureServiceConnectionId)
              appType: 'webAppLinux'
              appName: $(webAppName)
              package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
              runtimeStack: 'PYTHON|3.11'
              startUpCommand: 'startup.txt'
              deploymentMethod: 'auto'

My startup command is :

gunicorn -w 4 -k uvicorn.workers.UvicornWorker --timeout 600 -b 0.0.0.0:8000 app:app

and its giving me error as

##[error]Failed to deploy web package to App Service.

##[warning]Can't find loc string for key: KuduStackTraceURL

##[error]KuduStackTraceURL https://:@ai-commission-dsbfcbduhcb6gtfz.scm.eastus2-01.azurewebsites.net/api/vfs/LogFiles/kudu/trace

##[error]Error: Error: Failed to deploy web package to App Service. Conflict (CODE: 409)

##[warning]Error: Failed to update deployment history. Error: Bad Request (CODE: 400)


Solution

  • This Steps Solve My Error:-

    1. Access the Debug Console: First, I went to the Kudu Debug Console. You can access it by appending /DebugConsole to your app service URL. For example: https://<your-app-name>.scm.azurewebsites.net/DebugConsole

    2. Navigate to the Site Folder: Once inside the Debug Console, I navigated to the directory: /home/site/wwwroot

    3. Clean the Folder: I deleted all existing files and folders inside wwwroot. You can do this either through the file explorer in the console or by running: rm -rf /home/site/wwwroot/*

    4. Redeploy the App: After clearing the contents, I triggered the deployment again (using my CI/CD pipeline or deployment method), and this time it worked successfully without any errors.

    Note: This issue usually happens due to leftover or corrupted deployment files. Clearing the directory ensures that your deployment starts fresh.