2
votes

We are using Slack to notify our development teams about production code releases. The way we've found to do this that allows us the most flexibilty is through a POST to our Slack app. In the body of the request I'm passing in 4 values, shown below, that are set up as parameters for the task group.

In the task group I have set up 3 parameters with default values, they are: Name value

  • applicationname $(Release.DefinitionName)
  • envionment $(environment)
  • team $(System.TeamProject)

Task Group Setup

I set up both a PowerShell script task to run inline. It does not have the option to pass in parameters. Right now I'm just writing the values to the console to see what's going on.

  • Write-Output "env $env:environment"
  • Write-Output "releaseurl $env:releaseurl"
  • Write-Output "team $env:team"
  • Write-Output "application $env:applicationname"

PowerShell Task

With my Bash script, I am doing the same using echo, and it looks like this:

  • echo env $(environment)
  • echo releaseurl $(Release.ReleaseWebURL)
  • echo team $(team)
  • echo application $(applicationname)

Bash Task

When I run these scripts PowerShell will only print a value for environment (which is defined in the release workflow). It is failing to use the default release variables, even.

  • 2019-04-11T13:23:58.6833137Z env production
  • 2019-04-11T13:23:58.6987109Z releaseurl
  • 2019-04-11T13:23:58.6997009Z team
  • 2019-04-11T13:23:58.6999878Z application

Bash, however, performs as expected.

  • 2019-04-11T13:24:17.3299022Z env production
  • 2019-04-11T13:24:17.3404876Z team App Services
  • 2019-04-11T13:24:17.3405018Z application Release Notification Pilot
  • 2019-04-11T13:24:17.3838219Z releaseurl https://thereleaseurl

Bash does not have an issue using the System/Release variables. PowerShell will only use whatever variables it finds explicitly defined in the VSTS Release Variables. I want it to use the values of the task group parameters which will allow the teams to use default or custom values.

So, the PowerShell script would use the applicationname variable, which is defaulted to $(Release.DefinitionName). In the release workflow, teams could leave this as is, or use a custom value if the definition name isn't clear enough or desired for the reported name in the alert. The only way I can get this to work is define applicationname in the release variables, and set its default there to $(Release.DefinitionName).

Again, the bash script works great. The powershell script doesn't seem to like this. Does anyone have an idea on why? Will be happy to try about anything.

1

1 Answers

0
votes

The $env:variable syntax makes powershell retrieve the values from the environment variables at runtime. The $(variable) syntax performs the inlining of variables before handing the script to powershell.

Hence the $env:variable isn't captured as a variable usage for the task group, while $(variable) is.

The inlining-before-execution can cause issues when the variables contain quotes or other special characters that require escaping.

Ideally you'd pass the variables as arguments to the script invocation and not as inline values in the script block.

When running a script-block, you can explicitly register the variables you want to make available in the Environment Variable section:

enter image description here