0

I need to use a predefined Azure DevOps variable in a release pipeline. I'm working with several artifacts, and I need to get project name from each.

So, in an Inline PowerShell step, I try to use

RELEASE_ARTIFACTS_{ARTEFACTNAME}_PROJECTNAME

But the interpolation doesn't work as wanted .. I tried following without success:

$ProjectName = $("RELEASE.ARTIFACTS.$($var.name).PROJECTNAME")

Unfortunately, the result is always

"RELEASE.ARTIFACTS.varname.PROJECTNAME" and not the ADO project name

2
  • IIRC, those variables are referenced $(var.name). It's not a subexpr. Commented Apr 7, 2020 at 13:57
  • Let me detail a bit more: $($var.name) = "REPOS1" $(RELEASE.ARTIFACTS.REPOS1.PROJECTNAME) = PROJECT1 But, when I tried to get the value "PROJECT1" from my script by executing $("RELEASE.ARTIFACTS.$($var.name).PROJECTNAME"), I get result equals to "RELEASE.ARTIFACTS.varname.PROJECTNAME" instead of "PROJECT1" Commented Apr 7, 2020 at 14:49

1 Answer 1

1

You may have to hard code the artifacts alias name in the expression.

#REPOS1 is the artifacts alias defined in release pipeline Artifacts-->Source alias

$ProjectName = $(Release.Artifacts.REPOS1.ProjectName) 

You cannot wrap another $() inside $() like this $(a.$(b).c) in azure pipelines. Azure pipeline cannot resolve this kind expression $($()).

Below expressions will not work:

$alias = "Artifacts1"
$ProjectName = $(Release.Artifacts.$($alias).ProjectName)

$ProjectName = $(Release.Artifacts.$(arifactName).ProjectName)
Sign up to request clarification or add additional context in comments.

4 Comments

My problem is that I have several artifacts, that's why I have to build it in PowerShell.
how were the artifacts added to your release pipeline. Are them added separately or in one artifacts. When you add a artifacts, you can define its alias name in the Source alias field, which you can use to identify them. Could share a screenshot?
Is it the case that you have to decide the alias name by some kind of condition in the powershell task?
@gerem even if you have multiple artifacts if you do not add them dynamically you have fixed number of them. I know that this is not the best approach, but from what we see here it is the best approach we can have. I also tried to find better approach, but it must be like Levi Ls-MSFT says.

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.