Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Automate version number in package.json with Jenkins

Here is my package.json looks like:

{ "name": "Myproject",
"version": "0.4.13",

Note:Here 4 is not the minor version.0013 is minor

"dependencies": {
"lodash": "^4.0.0",
"vinyl-fs": "2.2.1"
},
"repository": {},
"devDependencies": {
.........
......

How can I automate versioning of package.json using Jenkins build.

Required format should be: 0.4.13-$BUILD_NUMBER So far I try to do it using sed command:

sed -i "s/version: .*/version: 0.4.13-$BUILD_NUMBER/" package.json

But it's not updating version number in package.json file. Also used

npm version 0.4.13-$BUILD_NUMBER

FYI:The generated build artifact should look like 0.0013-1.war

like image 987
Happy Avatar asked Oct 13 '16 02:10

Happy


1 Answers

If you're using grunt, you could use the recommendation here.

Alternatively, there's a built in function in npm that does this for you. Run npm version, docs here.

like image 133
Dandy Avatar answered Sep 18 '22 18:09

Dandy