Sam
Sam

Reputation: 7058

Set variable in bash script and access in expression in Azure Pipelines

I am using an azure-pipelines.yml script to source control my build pipeline.

In a task I have defined a bash script to set some variables for certificates paths depending on whether we are building for production or anything else:

 steps:
  - bash: |
      echo "Building for $BUILD_SOURCEBRANCHNAME"
      if [ "$BUILD_SOURCEBRANCHNAME" = "production" ]; then
        echo "##vso[task.setvariable variable=configuration]Release"
        echo "##vso[task.setvariable variable=certificatesPath]${{ parameters.productionCertificatesPath }}"
      else
        echo "##vso[task.setvariable variable=configuration]Staging"
        echo "##vso[task.setvariable variable=certificatesPath]${{ parameters.stagingCertificatesPath }}"
      fi
    name: environmentVars

How can I then access these variables in an expression in a later build step in the same job? I know I can access them like $(environmentVars.configuration) and $(environmentVars.certificatesPath), but this syntax doesn't work for expressions. Here is where I'm trying to access the variables:

signingProvisioningProfileFile: ${{ format('{0}/app.mobileprovision', <ACCESS VARIABLE HERE>) }}

Upvotes: 5

Views: 7132

Answers (1)

Sam
Sam

Reputation: 7058

My solution to this was to just bake the constants I wanted into the initial setting of the variable instead of trying to format it later. For example:

echo "##vso[task.setvariable variable=certificatesPath]${{ parameters.productionCertificatesPath }}/app.mobileprovision"

Upvotes: 2

Related Questions