How to Add Environment Specific Variables to Library Variable set using Powershell Rest Api

I was referring to some of the links here

However can not find any reference code for adding new variable having different value per scope to the Library variable set using REST Api.
Do you have any reference code for same?

Hi @harsh_tech,

Thanks for getting in touch!

We have a sample script for adding or editing project variables with scoping available.
This should hopefully be able to demonstrate how to apply scoping via the API and you may be able to modify it to target library variable sets rather than project variables without too much work.

Regards,
Paul

Thanks @paul.calvert but the main problem I am facing with this REST API is that I can not add different value per environment. The example also does not demonstrate that, its rarely someone would have same value for all environment. Can you please provide sample on how to do that ?

The script provided can add variable values with environment scoping. To add multiple values you would need to use a separate command for each one.

e.g.

    Add-Variable -VariableSet $octopusProjectVariables -VariableName "Test" -VariableValue "Dev Value" -VariableEnvScope "Dev"
    Add-Variable -VariableSet $octopusProjectVariables -VariableName "Test" -VariableValue "Prod Value" -VariableEnvScope "Prod"

1 Like

Thanks Paul.

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.