A package.json file must contain Name and Versoin fields inside the json. The name field consists with package's name, and must be in lowercase and one word and may contain hyphens and underscores. The version field must be in x.x.x and and see the guidelines below,
Using awk command,
$ awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json > VERSION
$ awk '/name/{gsub(/("|",)/,"",$2);print $2}' package.json > APP_NAME
then, you can use it anywhere those values in your Jenkins or shell script,
$(cat APP_VERSION)
$(cat APP_NAME)
or you can pass to a variable also,
$ APP_VERION=`awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json`
$ echo $APP_VERSION
$ APP_NAME=`awk '/name/{gsub(/("|",)/,"",$2);print $2}' package.json`
$ echo $APP_NAME
Comments (0)