0

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.

Brandon Minnick
  • 11,396
  • 12
  • 55
  • 108
Jeeva
  • 142
  • 1
  • 9
  • Generally, you should perform a single build of your application, then transform the config files appropriately at the time of **deployment**. – Daniel Mann Jul 06 '17 at 17:10
  • The build defintion builds Xamarin.Android projects so it will be apk file. Does your response still apply for mobile projects? – Jeeva Jul 06 '17 at 17:22
  • There is only one app secret per app in Mobile Center, where would you get the other app secrets from? Or are you talking about generic secret variables? Either way, we're working on support for build scripts in Mobile Center and would love your feedback via the blue support button. Disclaimer: I work on the Build service of Mobile Center. – Matthias Wenz Jul 06 '17 at 20:22
  • @Mathiaswenz The apps built in different build configuration will be deployed to apps in the Mobile center. Debug app -> Mobile Center debug app, Release app -> Mobile Center debug app, etc. So we will have dedicated app secrets from Mobile Center to configure with. While compiling the source using the build configuration should add corresponding app secret in the source. I have just now found a way; that we could use Multi-Configuration feature in VSTS build and a custom script that replaces the correct app secret based on the active build configuration. I am yet to write that script. – Jeeva Jul 06 '17 at 22:00
  • You can use release management instead: with 3 environments to deploy your debug app, release app and ad-hoc app to mobile center separatly. More details about release, you can refer https://www.visualstudio.com/en-us/docs/build/concepts/definitions/release/what-is-release-management. – Marina Liu Jul 07 '17 at 03:00

1 Answers1

1

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"
starian chen-MSFT
  • 31,056
  • 2
  • 22
  • 47