5

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>) }}
4
  • What is signingProvisioningProfileFile? Is that a build step parameter, or part of a Bash script? Commented Mar 5, 2019 at 1:42
  • its an input to a task @DanielMann Commented Mar 5, 2019 at 2:06
  • $(configuration) and $(certificatesPath). If it's in another stage in the yaml file you'll need to use isOutput=true on your task.setvariable Commented Mar 5, 2019 at 10:56
  • Possibel duplicate: stackoverflow.com/q/53154702/736079 Commented Mar 5, 2019 at 10:56

1 Answer 1

2

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"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.