如何通过Azure DevOps实现Bitbucket仓库指定文件夹变更的自动化部署至Azure Web App
Alright, I’ve worked through similar scenarios before—let’s get this automated pipeline set up exactly how you need it. The key here is to narrow down the trigger to only the Theme folder in your DEV branch, and then deploy just that folder to your Azure Web App without touching anything else.
First, create a new project in Azure DevOps (or use an existing one). Then:
- Go to Pipelines > Pipelines and click New pipeline
- Select Bitbucket Cloud as your source (you’ll need to authenticate and grant access to your WPTheme repository)
- Choose the DEV branch when prompted, then select Starter pipeline to generate a base YAML file—we’ll edit this next.
We need to make sure the pipeline only runs when changes are made to the Theme folder in the DEV branch. Update the trigger section of your YAML like this:
trigger: branches: include: - DEV paths: include: - Theme/** # Matches all files/subfolders inside Theme exclude: - '*' # Excludes everything else to avoid false triggers
We don’t need to build the entire repo—just package the Theme folder into a zip artifact that we’ll deploy. Add these steps to your YAML:
steps: # Archive the Theme folder (without including the parent "Theme" folder in the zip) - task: ArchiveFiles@2 inputs: rootFolderOrFile: 'Theme' includeRootFolder: false archiveType: 'zip' archiveFile: '$(Build.ArtifactStagingDirectory)/theme-deploy.zip' replaceExistingArchive: true # Publish the zip as a pipeline artifact - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)/theme-deploy.zip' ArtifactName: 'theme-artifact' publishLocation: 'Container'
The includeRootFolder: false ensures that when we deploy, the files go directly into the target Theme folder in your Web App (instead of creating an extra nested folder).
Now we’ll deploy the packaged zip directly to the Theme folder in your Web App. Add this final step (replace the placeholder values with your actual Azure resources):
# Deploy to Azure Web App, targeting the existing Theme folder - task: AzureWebApp@1 inputs: azureSubscription: '<Your Azure Service Connection Name>' appType: 'webApp' appName: '<Your Azure Web App Name>' package: '$(Pipeline.Workspace)/theme-artifact/theme-deploy.zip' deploymentMethod: 'zipDeploy' # Specify the exact target path in your Web App additionalArguments: '-dest-path "site/wwwroot/Theme"'
- For Linux Web Apps, change the
dest-pathto/home/site/wwwroot/Theme - Make sure you’ve set up an Azure Service Connection in Azure DevOps (under Project Settings > Service connections) with permissions to deploy to your Web App.
- Test the pipeline manually first: Go to your pipeline in Azure DevOps, click Run pipeline, select DEV, and verify it packages and deploys correctly.
- Make a small change to a CSS/JS file in the Theme folder of your Bitbucket DEV branch—this should automatically trigger the pipeline and update the Web App’s Theme folder.
内容的提问来源于stack exchange,提问作者Saad Zulfiqar

