I need to make an automatic bump of package.json in jenkins, and really stuck with it.
The following sed
command works in a pipeline but it changes the second field, I need to change the third one:
sed -i "/version/s/\\([.]\\)\\(.\\)\\(.*\\)/\\1${BUILD_NUMBER}\\3/" package.json
Output:
"version": "0.222.0"
but I need:
"version": "0.0.222"
a part of json input:
{
"name": "render",
"version": "0.0.0"
"description": "",
"main": "./dist/index.js",
"bin": {
"render-ne": "./bin/re"
},
Who can assist with it?
Assuming the field format is as was presented, (i.e.: "version": "0.0.0"
), then those back references aren't really necessary here. Just s
ubstitute the text after the final .
:
sed -i '/version/s/[^.]*$/'"${BUILD_NUMBER}\"/" package.json