phpazureazure-devopsazure-pipelinesazure-pipelines-yaml

Azure DevOps - Build and Deploy simple PHP Web App


I am trying to build and deploy a simple php app with index.php file using CI/CD and following this link. Below is the yaml file that has been configured and the build pipeline is executed successfully.

# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/php
 
trigger:
- main
 
variables:
 
  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: 'phptestapp-connection'
  
  # Web app name
  webAppName: 'phptestapp'
  
  # Resource group
  resourceGroupName: 'MyResourceGroup'
 
  # Environment name
  environmentName: 'phptestapp'
 
  # Agent VM image name
  vmImageName: 'ubuntu-latest'
  
stages:
- stage: Archive
  displayName: Archive stage
  jobs:  
  - job: Archive
    displayName: Archive
    pool:
      vmImage: $(vmImageName)
    steps:   
    - task: AzureAppServiceSettings@1
      inputs:
        azureSubscription: $(azureSubscription)
        appName: $(webAppName)
        resourceGroupName: $(resourceGroupName)
        appSettings: |
          [
            {
              "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
              "value": "true"
            }
          ]
    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true
 
    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop
 
- stage: Deploy
  displayName: Deploy stage
  dependsOn: Archive
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool: 
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:            
          - task: AzureWebApp@1
            displayName: 'Azure Web App Deploy: PHP Web App'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              appName: $(webAppName)
              runtimeStack: 'PHP|7.2'
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip

However, when I configure and run release pipeline, it throws exception as below

> Error: No package found with specified pattern:
> D:\a\r1\a\**\*.zip<br/> Check if the package mentioned in the task is
> published as an artifact in the build or a previous stage and
> downloaded in the current job.

P.S. Adding below in build pipeline yaml file is not making any impact

- task: PublishBuildArtifacts@1

The idea is to develop a CI/CD for a simple PHP web app and later implement the same concept to PHP framework like Wordpress/Laravel/Magento2

Open to ideas and suggestions


Solution

  • Try to replace

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop
    

    to

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        ArtifactName: 'drop'
        publishLocation: 'Container'