Save Azure CLI command Output using inline script in DevOps - azure-devops

I've been trying to store the output of multiple az cli commands in a variable defined in my pipeline with 0 success.
This being my last attempt:
The way I try to make sure is getting pass to the var is by doing an echo, which it outputs this(in all attempts):
At the end what im trying to achieve is to get the key value stored to use later:
Any suggestions on how to do this in the Azure CLI task from Azure DevOps Pipeline?
PS: Have being trying some commands from shell and batch and must of the attempts failures are related to not recognizing commands(batch/shell) inside the script. Which is confusing since in Azure cli task Docs:
Answer
#4c74356b41 Answer helped a lot since I didn't know I could do query in azure cli commands to get a specific value of a command. But it didn't quite answer my questions. All that said, this link Set Output Variable in Azure CLI task on VSTS has the Answer to my question.

just use query path filtering, something like this:
--query 'properties.properties.sites[0].key' -o tsv
this should output only the key you are interested it. reading:
https://learn.microsoft.com/en-us/cli/azure/query-azure-cli?view=azure-cli-latest

Related

How to read release pipeline variable and use as environment variable in Azure DevOps in Azure CLI task?

I am using one powershell task and one Azure Cli task in release pipeline of Azure DevOps.
I have some release pipeline's variables. I want to read those variables as they will be required by my script in above two tasks. I used powershell core in Azure cli task
I tried to read them in the inline script directly as $(variableName) or $env:variableName but none of the above worked.
I tried to set read the variable in Environment variables option in the task and then use in the inline scripts using $env:variableName but it also didn't work. On printing the variableName in the script using Write-Host, the value I got is $(valueName) instead of the correct value.
How to read those variables inside these scripts?
The pipeline variables can be reference in the Azure CLI inline script by using the syntax $(variableName). I tested by adding the following in a script
write-host "The variable value: $(variableName)"

Azure Devops environment variable not resolving in task

In an Azure Devops Build pipeline, I'm setting an environment variable in Powershell, like below:
And i know the variable works in another powershell task, because of this test:
But I'm not able to actually use this in another, non-powershell task. See this docker build/push task where i'm trying to add a tag. I get an error saying that it can't find that variable. Is my notation wrong somehow? I've tried multiple different variations on the screen shot below, but none have worked.
The notation $env:LOCALTAG is powershell specific. I think you should use the macro syntax $(LOCALTAG) (without $env)
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#macro-syntax-variables.

Powershell variable over azure devops variable

I am trying to pass PowerShell variable to an Azure Devops variable in pipeline during runtime but unable to pass them successfully. Could someone guide the correct syntax to apply escape sequence?
Azure devops pipeline variable:-
foo_ABC = abcdefghigklmnopqrstxyz
env= abc
Powershell task in pipeline:-
$environment= "$(env)".ToUpper()
$temp= "foo_$($environment)"
Write-Output "$($temp)"
Output:-
Expected: abcdefghigklmnopqrstxyz
Actual: (foo_ABC)
For this issue , the value of nested variables (like $($temp) are not yet supported in the pipelines. You can refer to this case to see this point.
As a workaround, you can try to use the Variable Toolbox task.
You can refer to this case for this task.

Read Octopus variables

I am new to octopus and have a bunch of steps. For each steps we have "Machine Roles".
As part of the steps I have a script tasks/step and I wish to access the roles assigned to this step in the (powershell) script. How can I achieve this.
I tried a few things, i.e. Octopus.Machine.Roles, Octopus.Tentacle.CurrentDeployment.TargetedRoles in the (powershell) script. But does not see anything.
As found in this example, if you have a variable in Octopus, you can access it using the variable name, prefixed with a $ in PowerShell, so for a variable TestUrl use:
$TestUrl
For Octopus Parameters, you use the following:
$OctopusParameters['Octopus.Machine.Roles']
This should give you access to all the system variables.

Jenkins CLI get test result

I am trying to find out if there is a command in the Jenkin's CLI, that provides you with an xml, txt, html or some file with test results from a job that was just executed. Does any one know of such command or way to do this?
The reason I'm asking is that I'm creating a job from an xml file via Jenkin's CLI. Then, I'm executing the job I just created and once the job is complete, I'd like to use a command and get the test results.
Thank you in advanced
David
You can just save the results of your test as artifact, and download it, as the url is known to be something like http://jenkins.yourcompany.com/job/yourjob/buildId/artifact/testResults.xml