2

I have a variable defined in Azure devops variable group like below:

apple-prod-branch  refs/heads/release-823T0709

The above variable works when called in azure pipeline powershell command when called like:

"Write-Host $(apple-prod-branch)" 

Output is: 
refs/heads/release-823T0709

In the above variable name apple-prod-branch, apple is the repo name. How can I use the repo name and use a variable like this ?

$repo_name = "apple"

"Write-Host $($(repo-name)-prod-branch)"

End result needs to be

refs/heads/release-823T0709
1
  • Is this being queue from the appl repository or is this something where a value needs to be reference to a specific version of a separate repo? Commented Feb 4, 2022 at 2:54

1 Answer 1

2

How can I use the repo name and use a variable like this ?

You can use the following PowerShell Script:

$test = "$(repo-name)-prod-branch"

$branch= [Environment]::GetEnvironmentVariable($test)

echo $branch

Result:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I am getting the below error. At C:\agent\_work\_temp\54b8dea2-f26e-4281-bc85-e37f4c2bcffa.ps1:3 char:6 + $repo-name = "apple" + ~~~~~ Unexpected token '-name' in expression or statement. At C:\agent\_work\_temp\54b8dea2-f26e-4281-bc85-e37f4c2bcffa.ps1:3 char:1 + $repo-name = "apple" + ~~~~~~~~~~ The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such as a variable or a property. + CategoryInfo : ParserError: (:) [], ParseException + FullyQualifiedErrorId : UnexpectedToken
This is my powershell step in the pipeline: $repo-name = "apple" $test = "$(repo-name)-production-release-branch" $branch= [Environment]::GetEnvironmentVariable($test) echo $branch
I purpose here is to store the repo names using azure devops api in an array and check if the variable format like $(repo-name)-production-release-branch exists in the variable group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.