Tuesday, August 11, 2020

Azure DevOps Pipeline Runtime parameter Task Condition

 Azure DevOps Pipeline Runtime parameter Task Condition


    This guide explains you how to use Azure DevOps pipeline to pass runtime boolean values and run tasks only if condition is true else skip the task.


- Add following lines at the beginning of your pipeline YAML file


parameters:
nameinstallNewRelic
  typeboolean
  defaultfalse

trigger:
  branches:
    include:
    - qa
  paths:
    include:
    - '*'
    exclude:
    - 'docs/*'
    - '*.md'

pr:
  branches:
    include:
    - qa

variables:
  drupalroot'/usr/share/nginx/html'
  docroot'/usr/share/nginx/html/docroot'
newrelic_cmd'docker run --entrypoint /bin/mv $(containerRegistry)/$(imageRepository):latest'

stages:
stageReleaseToQA
  conditionand(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/qa'))
  displayNameRelease to QA
  jobs:
  - jobRelease
    displayNameRelease
  - deploymentDeployToQA
    environment$(webAppNameQA)
    strategy:
      runOnce:
        deploy:
          steps:
         ...
Other Tasks
...
# Below Task will only be executed if condition is true, default value is
# false in parameter. When you click on run pipeline it will ask you the
# parameter value i.e. installNewRelic if you select then condition becomes
# true and below task will executed else it will be skipped.
# Refer the screenshot below
taskBash@3
             displayName'Place newrelic.ini from /usr/share/nginx/html/docroot/profiles/'
             conditionand(succeeded(), eq('${{ parameters.installNewRelic }}', true))
             inputs:
               targetType'inline'
               script: |
                 $(newrelic_cmd) $(docroot)/profiles/corp-qa-newrelic.ini /etc/php/7.3/mods-available/newrelic.ini