Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add or replace element in array of Appsettings.Json on Azure Devops #131

Open
Lekiniu opened this issue Feb 17, 2021 · 3 comments
Open

add or replace element in array of Appsettings.Json on Azure Devops #131

Lekiniu opened this issue Feb 17, 2021 · 3 comments

Comments

@Lekiniu
Copy link

Lekiniu commented Feb 17, 2021

I am trying to add or replace element in array of Appsettings.Json on Azure Devops release pipeline. I can't find instruction how to do it via magic chunks config transformation.But I know that it is possible after 2.0 version.
How to add or replace element in array for the following code :
{
"my_array" : [
{"value" : 1},
{"value" : 5}
]
}

@Lekiniu Lekiniu changed the title add or replace element in array of appsetting. azure devops add or replace element in array of Appsettings.Json on Azure Devops Feb 17, 2021
@NekidMugh
Copy link

You should be able to use "my_array/@value" = x.

@Akinnagbe
Copy link

I tried to replace something like this
"IDPClientSettings/Scopes":["openid","profile","offline_access","api"],
it returned this

Transformation found: IDPClientSettings/Scopes: openid profile offline_access api

How can I fix that?

Thanks

@NekidMugh
Copy link

NekidMugh commented Jun 30, 2021

This tool from my experience isn't great at changing arrays. Had similar issues and had to get creative with the solution. If you are trying to replace those settings for each environment, my suggestion is to have a Powershell script to blank out each option in the array.

((Get-Content -path "_{FILE PATH}_" -Raw) -replace '"openid",','') | Set-Content -Path "_{FILE PATH}_"
((Get-Content -path "_{FILE PATH}_" -Raw) -replace '"profile",','') | Set-Content -Path "_{FILE PATH}_"
((Get-Content -path "_{FILE PATH}_" -Raw) -replace '"offline_access",','') | Set-Content -Path "_{FILE PATH}_"
((Get-Content -path "_{FILE PATH}_" -Raw) -replace '"api",','') | Set-Content -Path "_{FILE PATH}_"

Then with magic chunks insert new array values:

"IDPClientSettings/Scopes[]`0": "value1",
"IDPClientSettings/Scopes[]`1": "value2",
etc...

What I found with the arrays is that it does not modify them but add a new entry. So if you went with just trying to modify the first entry in the array with the "IDPClientSettings/Scopes[]`0": "value1" what it would do is add value1 to the end of the array and ignore what was already there resulting in..."openid","profile","offline_access","api","value1". Play with this and see if it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants