Is there a way to use VSTS Variable Groups per environment?

前端 未结 3 1382
南笙
南笙 2020-12-11 19:56

I\'m moving my configuration from using web.config transforms to being based on VSTS variables. I get process variables, you define a variable, pick an environment, and you

3条回答
  •  不知归路
    2020-12-11 20:17

    I ended up using a powershell script to define my process variable based on the variable groups, it works great.

    Let's say I want a variable named "LoggingConnectionString" and this has different values per environment

    Steps:

    1. Define a Variable group, e.g. "SharedLoggingVariables"
    2. Inside this Variable group, define a variable/value for each environment, e.g. "LoggingConnectionStringDev", "LoggingConnectionStringProduction"
    3. Back in your Process Variables for the Build/Release, make SURE you don't have a variable named "LoggingConnectionString", otherwise this will overwrite the value coming from the variable group
    4. In your Release process, create a Powershell inline script at the beginning of the Agent with the following code

    Param(
       [string]$LoggingConnectionString
    )
    
    Write-Host "##vso[task.setvariable variable=LoggingConnectionString]$LoggingConnectionString"
    
    1. Pass your variable group as an argument to this inline powershell, e.g.

      -LoggingConnectionString "$(LoggingConnectionStringDev)"

    The final powershell step should look something like this:

    During release, the powershell will set your process variable from the variable groups. If powershell isn't an option for you, there are other options

提交回复
热议问题