Reputation: 31
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
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.
With my Bash script, I am doing the same using echo, and it looks like this:
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.
Bash, however, performs as expected.
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.
Upvotes: 3
Views: 1115
Reputation: 114481
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:
Upvotes: 1