Is there a solution to source the app secrets for different build configuration in VSTS Build definition

292 Views Asked by At

We are trying to create one build definition to build multiple build configuration. The app uses Mobile Center App secret which will be different for apps built in various configuration. Is there a way to source only the app secret for a particular build configuration without specifying all app secret in the same config.

I have just drawn it to explain bit better. enter image description here

The app output will go into repositories for each configuration.

1

There are 1 best solutions below

0
On

Refer to these steps to do it:

  1. Add variables and set corresponding values per to configurations (AppDebug, AppHoc, AppRelease)
  2. Add PowerShell task (Trpe: Inline Script)

Script:

switch ($env:BuildConfiguration) 
    { 
        "debug" {Write-Host "##vso[task.setvariable variable=actualSecret;]$env:AppDebug"} 
        "release" {Write-Host "##vso[task.setvariable variable=actualSecret;]$env:AppRelease"} 
        "Hoc" {Write-Host "##vso[task.setvariable variable=actualSecret;]$env:AppHoc"} 
          default {Write-Host "##vso[task.setvariable variable=actualSecret;]$env:AppDebug"}
    }

After that set app secret for your app by using actualSecret variable.

Logging Commands

Note: if you are using secret variables, you need to pass them through arguments, for example:

 param(
    [string]$appRelease
    )

Write-Host "##vso[task.setvariable variable=actualSecret;]$appRelease"

Arguments: -appRelease $(appRelease)

BTW, if the build agent doesn't support PowerShell, you can use other task, such as Batch Script.

echo "##vso[task.setvariable variable=sauce]crushed tomatoes"