Anil Paul

Web Developer – Designer

Azure Laravel CI Pipeline

CI YAML for laravel

first specify the branch to trigger build:

trigger:
  - master

pool and version set up:

pool:
  vmImage: ubuntu-latest

variables:
  phpVersion: 7.4
composer install
- script: |
      sudo update-alternatives --set php /usr/bin/php$(phpVersion)
      sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
      sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
      sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
      sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
      sudo a
      php -version
    displayName: 'Use PHP version $(phpVersion)'

  - script: composer install --no-interaction --prefer-dist
    displayName: 'composer install'
run tests
 - script: php artisan test
    displayName: 'php artisan test'
copy the env file securely stored in azure dev ops

Please refere azure documentation here

  - task: DownloadSecureFile@1
    displayName: 'Download .env file from secure file library'
    inputs:
      secureFile: .env
npm install
 - script: npm install
    displayName: 'npm install'
Archieve and publish Artifacts
  - task: ArchiveFiles@1
    displayName: 'Archive files'
    inputs:
      rootFolder: '$(System.DefaultWorkingDirectory)'
      includeRootFolder: false
      archiveType: zip

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'

All together

# PHP
# Test and package your PHP project.
# Add steps that run tests, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/php

trigger:
  - master

pool:
  vmImage: ubuntu-latest

variables:
  phpVersion: 7.4

steps:
  - script: |
      sudo update-alternatives --set php /usr/bin/php$(phpVersion)
      sudo update-alternatives --set phar /usr/bin/phar$(phpVersion)
      sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpVersion)
      sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpVersion)
      sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpVersion)
      sudo a
      php -version
    displayName: 'Use PHP version $(phpVersion)'

  - script: composer install --no-interaction --prefer-dist
    displayName: 'composer install'

  - script: php artisan test
    displayName: 'php artisan test'

  - task: DownloadSecureFile@1
    displayName: 'Download .env file from secure file library'
    inputs:
      secureFile: .env

  - script: sudo npm install -g npm@latest && npm install
    displayName: 'npm install'

  - task: ArchiveFiles@1
    displayName: 'Archive files'
    inputs:
      rootFolder: '$(System.DefaultWorkingDirectory)'
      includeRootFolder: false
      archiveType: zip

  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'