How to use Output Variables in Release pipeline - azure

I searched all the docs about Output Variables are for build pipeline and only told me how to set in .yaml. But how to use it in release pipeline?
Supposed I have 2 variables $abc="123" $def="456" in step Login. How to set them in below text box? and How to use them in step Deploy?

Some tasks define output variables
For brief text, it represents the follow scripts:
echo "##vso[task.setvariable variable=abc;isOutput=true]123"
Just specify the reference name in the blank of task, and then, you can call this output variable abc by using the format: <reference name>.<variable name>.
For example, if you specify the reference name as mycustom, just call the output variable by using $(mycustom.abc).

Related

Assign Azure Powershell variable to DevOps Pipeline variable

How can I assigned the $NewIP variable precalculated in this step to a DevOps pipeline variable called $pipeline_ip?
You should use logging command if you want to assign powershell variable to Azure DevOps variable
echo "##vso[task.setvariable variable=pipeline_ip;]$NewIP"
Update after clarification:
If you use syntax like:
$NewIP = $(pipeline_ip)
Then $(pipeline_ip) would be replaced with the value before script will be executed.
And if you use syntax like
$NewIP = $env:PIPELINE_IP
then you will refer to environment variable and since all DevOps variables are mapped (except secret variables - here you need to express this excplicitly) it would also work.
However, these are two ways of doing that.
You can use two methods:
$NewIP = $(pipeline_ip) Macro syntax variables
$NewIP = $env:PIPELINE_IP Set variables in pipeline

Get current branch name

I'm running a script (bitbucket_pipelines.yml) and on one of the steps I need to know the current branch name, How can I get it?
I saw there is a predefined BITBUCKET_BRANCH variable, but I'm having troubles to print it so I can see its content.
I tried to do:
...
step:
script:
- echo $BITBUCKET_BRANCH
but when pipelines runs all I see is
echo $BITBUCKET_BRANCH
How can I really see the content of this variable?
I found that Bb Pipelines are sometimes picky when dealing with variables. Try changing this to echo "$BITBUCKET_BRANCH". Also, enclosing the whole line in single quotes might help.
#Shvalb, the question should be how to display the value of a variable in bitbucket pipeline.
I deal with bitbucket support on this matter before.
I want to echo a repo/pipeline variable to see the value and it is not showing correctly.
In my case, it was my repo variable conflict with my deployment/pipeline variable. However, from the support, I understand bitbucket is using search and replace the screen value to "hide" the actual value of the variable with direct echo.
in order to see the value, you can use
echo $VAR > /tmpfile
cat /tmpfile
It was the trick I used before but I am not sure whether it will still work.

Assign a Variable to Shell inline script of Azure release

I have an inline script where one of the command is the below one. How can i Replace LINUX_PASSWD with a variable in Azure release.
I have added LINUX_PASSWD and FILENAME as variable in Azure release pipeline but they are empty after release
sed -i 's/password/$(LINUX_PASSWD)/g' FILENAME
If you want to replace your variables with their values, use $(varable_name) template. In your case:
sed -i 's/password/$(LINUX_PASSWD)/g' $(FILENAME)
Check the documentation: Understand variable syntax, Using custom variables
To use custom variables in your build and release tasks, simply enclose the variable name in parentheses and precede it with a $ character. For example, if you have a variable named adminUserName, you can insert the current value of that variable into a parameter of a task as $(adminUserName).

Azure DevOps Yaml: Gaining secret variable out of Azure KeyVault Task from Variable

I'm trying to obtain a secret out of my KeyVault.
The variable name is secretVar.
Obtaining the secret like this: $(secretVar) works fine however I would like to retrieve it from a variable like this:
I keep getting command not found and I've no idea why this shouldn't be working.
So the name of the secret I want to extract is inside a bash variable. For this question I've simplified the problem but in my real use case I have a bash for loop which loops through secret names and inside the for loop I want to extract the appropriate value from the KeyVault with the corresponding secret name like this:
for secretname in secrets; do
echo $($secretname) # This should contain the value of the secret but gives command not found
done
If anyone has an idea what could be happening, any help is very appreciated.
Thanks in Advance!
Look at the syntax you're using.
variable=secretVar
You are creating an environment variable with the literal value secretVar
Then you try to execute the value of the variable $variable with $($variable). So it tries to run the command secretVar, which obviously doesn't exist, and you get an error message.
The syntax you're looking for is
variable=$(secretVar)
just like you used in the first echo command in the script.
If you don't want to run the variable value as a command, the syntax would be $variable, not $($variable)
$variable is the syntax for a Bash environment variable.
$(variable) is the syntax for referencing Azure DevOps variables.
First of all, the script keyword is a shortcut for the command-line task. The task runs a script using cmd.exe on Windows and Bash on other platforms. You need to pay attention to the agent you are using.
If you want to set variables in scripts, you can use task.setvariable logging command. For example:
- script: |
echo $(secretvar)
echo "##vso[task.setvariable variable=variable]$(secretvar)"
- script: |
echo $(variable)
You can find more detailed information in this document.

Azure DevOps - pipeline variables - special char issue $$

I am using DevOps pipeline to build and deploy to different environments
For one environment I am encountering this issue where i am using a Pipeline Variable with $$ in the value
For Example:
Password pipeline variable with value = $omeCla$$Password
When i deploy it fails and when i check the logs the password is displayed as $omeCla$Password. So basically when $$ are together it drops one $
For all variable i am using regex __VaraibleValue__ and its working fine
I have tried:
$omeCla$\$Password to try and escape and it displays as $omeCla$\$Password . So basically \ doesn't work.
I tried '$omeCla$$Password' to try and escape and it displays as '$omeCla$Password'
I want to keep this value as a normal pipeline variable before review
So basically how can I escape this?
Or should I add a Secret Token here in the replace token task (see screenshot below)? and then make the pipeline variable secret? If so, what should I set for Secret Token? Also, in app.config in my repo what should I use instead of the regex __VariableName__ that I use for normal variables?
The solution was to use 4 $. So if you have $$ together you need to add $$$$
Example: $someCla$$$$Password
#JaneMa-MSFT as requested
https://developercommunity.visualstudio.com/content/problem/1296808/azure-pipeline-how-to-escape-special-characters-in.html

Resources