Search code examples
azureyamlpipeline

How to create a new variable from a runtime variable in azure devops pipeline


- job: working_on_compute
  timeoutInMinutes: 180
  dependsOn: gettoken1
  variables:
    SCHEMA_SUFFIX: $[env.config.outputs['checkconfigtask.startdate'] ]
    ${{ if eq(length(variables['SCHEMA_SUFFIX']), 0) }}:
    DB_SCHEMA: ""
    ${{ elseif ne(length(variables['SCHEMA_SUFFIX']), 0) }}:
    DB_SCHEMA: "_$(SCHEMA_SUFFIX)"

Here SCHEMA_SUFFIX is a runtime variable. I need to make a dynamic calculation and find the DB_SCHEMA variable . How to solve this issue


Solution

  • As the variable SCHEMA_SUFFIX is a runtime variable we couldn't make any conditions with that variable. So I moved the condition check to the env part of the bash script and made the conditional statement there and set the variable to a new key like the below in a bash. enter image description here

     - job: working_on_compute
       timeoutInMinutes: 180
       dependsOn: gettoken1
       variables:
        SCHEMA_SUFFIX: $[env.config.outputs['checkconfigtask.startdate'] ]
        DB_SCHEMA: $[env.config.outputs['checkconfigtask.startdate'] ]