VSTS: Pass build/release variables into Powershell script task

前端 未结 4 1770
忘掉有多难
忘掉有多难 2020-12-04 16:32

Ideally, I would want to configure our Azure Web App application settings using build variables (on VSTS), for example:

We perform our publish tasks using P

相关标签:
4条回答
  • 2020-12-04 17:09

    It is worth mentioning here, that secret variables are not passed into scripts as environment variables (env: in PS). So accessible only if passed as parameters for a script, eg. -MyPassword $(Password). See https://docs.microsoft.com/en-us/vsts/pipelines/build/variables?view=vsts&tabs=batch#secret-variables

    0 讨论(0)
  • 2020-12-04 17:14

    You could have also used variable groups to achieve this, thus maintaining variables that are closely related, isolated from the build variables and from other groups of related variables. I have shown how to easily set this up in this answer.

    0 讨论(0)
  • 2020-12-04 17:19

    The variables have already been passed to PowerShell script when the build start. If I understand your question correctly, you want to use these variables together instead of specifying them one by one like following:

    PrepareAppSettings.ps1 -websiteName "MyWebApp" -appsettings $(AllVariables)
    

    Then there isn't any way to do this.

    If you want to reduce the strings passed to the PowerShell script, you can set the variable as following:

    VariableName: MyRandomService | Value:"MyRandomService" = xxxxxxxx

    Then you just need to call the PowerShell script with variable name passed.

    0 讨论(0)
  • 2020-12-04 17:27

    Build Variables are automatically passed to all the PowerShell scripts as environment variables.

    So if you have defined a variable myVar in the Variables section. You can access it as $env:myVar in your script. One thing to note here is that . is converted to a _. For eg. if your variable is myVar.config, you will access it in your script as $env:myVar_config.

    The available variables also include variables such as branch name, build number etc. To see all the available variables, run a dummy build/release definition and add a PowerShell task with inline type and run Get-ChildItem Env:. This will show you all the available environment variables and you can see all your custom defined variables.

    More details are available here

    0 讨论(0)
提交回复
热议问题