How to use JSON variables in an Azure DevOps pipeline - azure-devops

I'm not sure if this is possible as I've searched but couldn't find anything related, but didn't find anything saying it's not!
In my Azure DevOps build pipeline I have a variable which holds a JSON value e.g:
Is there anyway of using a value of a json variable within a task? I've tried (on the off chance) $(myJson.message) and $(myJson).message but these didn't work.
So do pipeline variables only support simple types? Or is there a way round this?

You could always use something like powershell's Convert-FromJson to create a json object, but there's no way to tell a random task "treat this variable value as an object, rather than a raw string". You'll have to parse it yourself.

Related

Conditional Variables in Azure Classic Pipelines

I'm trying to set up a variable in the Azure Build Pipelines Classic Editor to use conditional functions to determine its value. YAML is not an option (unless there's some way to inject YAML as part of a Classic build...?).
In my current scenario, the idea is that the variable would return one of a few possible string values (or empty string) depending on the branch that triggered the build.
I want something along the lines of this:
I fear this may be a YAML-only thing, but hopefully someone can tell me I'm wrong about that.
Like Matt mentioned in the comment, the best approach for this would be to use a script (powershell or bash) that will have the logic to set the variable.
For more details about how to set a variable, have a look at this documentation.

Passing PSCustomObject as a global Variable in Azure YAML pipeline

I am creating a build pipeline (YAML) with some "Powershell" task in it in which all are not inline scripts. I need to have a PSCustomObject that can be passed as a global variable (this param should be accessible across the pipeline). For example, it needs to be used like this. $myPSObject.value1 in first task, $myPSObject.value2 in second task etc. Is it possible?
Any leads would be much appreciated.
No, this is definitely not possible, what you can do, however, is cast it to json (compressed would, probably, make more sense) and then in your steps read it and cast it back to an object and work with it like you normally would. You'd need to use azure devops build variable for that, not powershell variable

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.

Process Workflow: Given key is not present in the dictionary in UiPath

I am doing UiPath level-3 Assignment 1. I have made all the workflows using Ui Studio and I am stuck in the process workflow. While I run the WFs, it says
Process WF: Given dictionary is not present.
I checked all the values and arguments and they seem correct too.
Also when I run the Process WF separately, it gets stuck for each loop and say
object reference not set to an instance of an object.
Could someone help resolving these issues? Thanks in advance.
You are passing null value/trying to get value from dictionary using the key which doesn't exist. Please also remember that before using dictionary you have to create it.
It will be easier to help if you can provide status window logs at least.
As you said - I checked all the values and arguments and they seem
correct too.
So just check for spaces in your config file from where you are reading data and putting them in Dictionary.
Second Possibility
which seems to me is just check your arguments via which you are passing your configuration dictionary to your workflow. are you passing it from main workflow to your child workflows.
just double check your arguments.
Regards..!!
Aksh

How to retrieve VSTS Build variables?

Is it possible to get the values for custom variables being used in the build? I know they can be dumped to the console output as per what this example describe. But still want to find an easier way to archive it.
http://www.codewrecks.com/blog/index.php/2017/08/04/dump-all-environment-variables-during-a-tfs-vsts-build/
There isn’t the easier way then the way you provided to retrieve build variables, the value of variable can be changed during the build time (Logging Command), so it’s better to retrieve the variable at the end of the build (the way you provided).
Note, the secret variables can’t be output as general text.