Azure DevOps YAML: Passing a variable from a variable group to a parameter in a template file throws type error - azure-devops

I am attempting to read a variable from a Variable Group in my YAML file and passing it on to a template file that consumes that value. The template file defines this parameter as a number and the variable group does indeed store this as a number.
Here I have my pipeline that is invoking the template stage-run-tests with the 4 parameters, 3 of which are read from a variable group.
The template accepts the 4 parameters and have them typed as number
However, when I try running the pipeline, I get an error stating that the parameter was expecting a number and what was passed in was not a number.
If I remove the strong typing and I simply use the parameters as is, then everything work fine.
Can anyone help me with what's happening here? What should I do to ensure that I can have the parameters typed and still have the pipeline pass in the value from the variable group?

Change the type: number to type: string, as there is no number type in a variable group.

Related

Azure Devops - How to access a variable group variable within another variable

The following Patch variable works perfectly when setup using the variables functionality within a Pipeline:
Major = 1
crmRelease = 91
Minor = 0
Patch = $[counter(format('{0}.{1}.{2}', variables['major'], variables['crmRelease'], variables['minor']), 030)
Result (on first run) = 1.91.0.30
However, when moving this to a Variable Group, whilst the Major, CrmRelase, and Minor variables are ok, the Patch variable isn't valid and fails. Must you reference Variable Group variables in a different way?
Must you reference Variable Group variables in a different way?
The issue for Patch does not been parsed is not relevant with the reference way to variable which stored at variable group. It just because the function parse does not supported in Variable group.
For further analysis, here let's do 2 tests(the first one is failed to get Patch value, but the second one can succeed).
One is put all of them into Variable group.
The another is putting Major, crmRelease, Minor into Variable group, but ** ** make Patch in Variables.
Here are their initial logs:
Putting all of them into Variable group:
Only store Patch into Variables, but make others still in Variable group:
You can see, only store Patch in Variables, the function of it can be parsed at compile time. For the one which store at Variable group, our system treat it as a normal value. We does not support the function parse process when it is from Variable group.
To make it not interrupt your build, please make sure the variable which contains the functions in it are located at Variables instead of Variable group.

Azure DevOps Release Pipeline Variable Nested/Composed/Expression

I have a release pipeline with a variable, but there doesn't seem to be any way to set the value of that variable to something that's evaluated at release time. For example, another variable.
Here's a real example:
All I want to do is set the value of MyExpressionBasedVariable to the value of MyOtherVariable.
All the docs and examples online seem to suggest it's possible, but I can't get it to work. I always end up with the literal string rather than the evaluated value.
I've tried using these different syntaxes:
$(MyOtherVariable)
$[variables['MyOtherVariable']]
${{variables['MyOtherVariable']}}
I've seen that you can define custom tasks to set variable names as part of the pipeline but this seems massively overkill.
Essentially all I want to do is rename a key vault secret to a different variable name for convention-based XML variable replacement in config files.
E.g. I have a secret called this-is-a-secret-name-which-is-a-different-naming-convention-to-my-connectionstrings but I need it in a variable called MySecret-ConnectionString.
How do I use the value of another variable in a release pipeline variable?
How do I use the value of another variable in a release pipeline variable?
As I test, what you set should be work. You can try to follow below steps to check if you still have this issue:
Create a new release pipeline without link any variable group.
Set the Variable like following:
Add a Run Inline Powershell task to output the value of the Variable:
Write-Output 'The value of MyExpressionBasedVariable is $(MyExpressionBasedVariable)'
Write-Output 'The value of $(MyOtherVariable) is $(MyOtherVariable)'
Then we could get the log:
So, what you set should be work, if this still does not work for you, then you need to make sure that the variable you describe in the question is the variable your actual test.
Besides, at this moment, the value of nested variables (like $(TestVar_$(Release.Reason))) are not yet supported in the build/release pipelines, check this thread for some details, so make sure there are no such nested variables in your project.
Hope this helps.

Set and use enviroment variables in multiple release tasks in TFS

I have a web application that I build and release using TFS. The release definition contains a task group with all the necesarry steps for the deployment of the web application.
What I want to do is to determine a certain value and store it in a variable to use later on in the release proccess in the other release tasks.
At this moment, the first step in de task group is a Powershell task that determines the necessary value and stores it in an environment variable using:
Write-Output ("##vso[task.setvariable variable=MyVar;]$var")
When I use this environment variable in the next Task (Again, a PowerShell task), it runs perfectly as expected using:
Write-Host "Doing stuf for: $env:MyVar"
It's when I want to use the variable as a parameter for (multiple) different task(s) when it gets weird. When the environment variable has no default value, the calculated value from the first PowerShell task is used and all is well. But TFS doesn't like it when environment variables have no default value and forces to provide one before being able to save the release definition again. When I provide a default value, the task that uses the variable as Task parameter uses the default value, instead of the calculated value. I would expect that the calculated value should be used, as the second PowerShell task ensures that the calculated value is properly stored.
So, the symptoms I see:
When not providing a default value, the code in scripts as wel as the task parameters use the calculated value
When providing a default value, the code in scripts use the calculated value and the task parameters use the default value
Is there something I do wrong, or am I using environment variables wrong and should I use a different method?
As I understand it, you want to define your variable in a powershell-task within the task group, but you are also being forced to provide a value in the environment variable, causing the variable sometimes to have the value set in the powershell, sometimes to have the value defined in the environment variable.
The solution is to just provide the name of the environment variable itself, so it always gets overwritten by the value you set in the powershell task.
Source: https://blogs.msdn.microsoft.com/harshillodhi/2016/11/29/vststfs-understanding-task-groups-and-its-various-use-cases-with-setvariable-logging-command/
Under the header "What is a setvariable logging command and how to use it with Task Groups?", three scenario's are referenced. It sounds like the second scenario may fit your needs.

Dictionary type input in the VSTS Build/Release Task

I have to create a VSTS Build/Release task extension which takes a dictionary as the input type.
I need to pass n number of parameters to the task and also the parameter name and the parameter value should be given dynamically (while configuring the CI and CD).
Is there any input type which is similar to the Variable section where we can specify the Key-Value pair and also we can add n number of variables.
You can take a look at the Azure RG task which has a key value input. See the overrideParameters input, it has a special editor extension.
EDIT: search for editorExtension and you will find more examples of grids.

How do I create and set variables in oozie workflows?

How do I set variables in Oozie workflows?
For example the workflow here has an ${output} variable but where would it be set?
Is 'output' a special word, and if so how do I create my own variables?
Update: I am using hadoop streaming with Python, not Java.
Output is not a special word. The value of this variable will be passed to this workflow during the execution time using job.properties file. You can see an example job.properties file where all the variables related cluster details, environment and many other are kept as variables.
You have to use any variable name instead of OUTPUT.it is a parameter name only.this parameter is used instead of the output file. It is used for storing the output value during the execution of workflow or coordinator sample only. The variable name should defined in your workflow/coordinator sample like as follows...
<param> OUTPUT=/user/${wf:user()}/${exampleRoot}/output-data/hive</param>
If you want to see that parameter file,check the path specified in the <param> tag.
Storing the value to that parameter like as follows.
store (alias) into '$OUTPUT';