Home > Software engineering >  How to pass PowerShell variable values dynamically via azure pipeline variables
How to pass PowerShell variable values dynamically via azure pipeline variables

Time:09-28

I want to pass the PowerShell variable values via azure pipeline variables. Below script is to remove old images from azure container registry. I don't want to pass the values directly as I mentioned in code, those values I need to pass via pipeline variables. I have tried something like this as shown in image highlighted in yellow color. I'm getting error. enter image description here

enter image description here Azure pipeline task like AZ CLI as shown in below enter image description here I'm Getting error like as shown in below enter image description here

Anyone can help me out this. Thanks in advance....

CodePudding user response:

You must define the variables outside of your scriptblock, below it is a section called Environment Variables, you can store them there like so: Environment variables stored with syntax Then you can call them up in the scriptblock as environment variable: $env:LocalDbDataSource


Also, did you mean to put the $ signs in the Pipeline variables table? As far as I'm aware they are not needed, you should just put the name of your variable.

Another good tip would be to put your variables in a variable group, that way you can centralize where you store the variables. You can add them in the Library section of the pipelines tab

CodePudding user response:

Earlier I have passed same variable name in both cases like PowerShell variable name and Pipeline variables, post changing the name in azure pipeline variables it's working as excepted. enter image description here enter image description here

  • Related