0

I am currently sending in a list of key value variables from octopus to my project into my prompt. These are read and set in my environment by the code below.

$testKeys = $OctopusParameters.keys | Where-Object {$_ -like "test.env.*"}
ForEach ($key in $testKeys)
{
    $value = $OctopusParameters[$key]
    $name = $key.subString(9) # remove test.env prefix
    $kubectlArgs += "--env=`"$name=$value`""
}

This is coming back as follows:

> --env="ASPNETCORE_ENVIRONMENT=integration" 
> --env="ConnectionStrings__MongoDB=my mongo connectgion string" 
> --env="ServiceConfiguration__MyJSONObjectConfiguration=[ {'MyID': 23, 'URL': 'http://google.com/', 'User': 'MyUser',
> 'Password': 'test', 'Domain': 'MyDomain', 'Key': 'myKey'} ]"

So as you can see, this works perfectly when it is a one to one, key = string value. The problem is that for the serviceConfiguration I am passing in a JSON object.

My code is grabbing the values I need like so

"ServiceConfiguration:MyJSONObjectConfiguration:0"

How do I configure me PS1 script to treat the serviceConfiguration as JSON object and not a string? Is it even possible?

4
  • What language is that? It looks almost like PHP. Commented Feb 24, 2020 at 22:07
  • I don't understand what you're trying to do. PS1 is a string, it can contain some escape sequences to display special values, but it doesn't know anything about JSON. Commented Feb 24, 2020 at 22:10
  • This is PowerShell v1, unrelated to bash $PS1 :P Commented Feb 24, 2020 at 22:11
  • @Barmar sorry it is a powershell script is there any way of setting into a JSON object or the propery way of doing it? Or should I just send the string back to my code and deal it with it there? Commented Feb 24, 2020 at 22:13

1 Answer 1

1

I am not sure you have provided enough information to solve your problem fully. One possibility is if the value starts with '[' then treat as JSON and use CovertFrom-Json.

Something like:

"[ {'MyID': 23, 'URL': 'http://google.com/', 'User': 'MyUser', 'Password': 'test', 'Domain': 'MyDomain', 'Key': 'myKey'} ]" | ConvertFrom-Json

Which gives an object like:

MyID     : 23
URL      : http://google.com/
User     : MyUser
Password : test
Domain   : MyDomain
Key      : myKey
Sign up to request clarification or add additional context in comments.

Comments

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.