I have a JSON file "appSettings.json" which has the following content:
{
  "Branch": {
    "Name": "test"
  },
}
My question is, how do I set the value "Branch.Name" to something else when running the bitbucket pipleline?
I have a JSON file "appSettings.json" which has the following content:
{
  "Branch": {
    "Name": "test"
  },
}
My question is, how do I set the value "Branch.Name" to something else when running the bitbucket pipleline?
 
    
    figured it out after checking this question.
- apt-get update
- apt-get install -y jq # install jq
- tmp=$(mktemp)
- jq '.Branch.Name = "prod"' appsettings.json > "$tmp" && mv "$tmp" appsettings.json
 
    
    You can use standard Bash/Shell commands to do a 'Find and Replace' inside a text file:
sedsed -i -e 's/"test"/"prod"/g' appSettings.json
# Delete the unwanted backup file, created by sed
if [ -e appSettings.json-e ]
then
    rm appSettings.json-e
fi
echo with Bash string substitutionUse this if you need to replace with special characters like "/" and "\", which sed cannot handle.
file_contents=$(< appSettings.json )
echo "${file_contents//\"test\"/\"prod\"}" > appSettings.json
More info and source: Find and Replace Inside a Text File from a Bash Command
