bamboopackage.json

Extract value of version defined in package.json in bamboo task


Is it possible to extract a package.json version value in a bamboo task? I want to extract the version field and save its value in a bamboo.variable.


Solution

  • Yes, try adding "Script" task into your Bamboo Job. In the script body you can add a code to read package.json version by using grep function from cat command output, and assign to a variable you like, e.g. PACKAGE_VERSION:

    # Version key/value should be on his own line
    PACKAGE_VERSION=$(cat package.json \
      | grep version \
      | head -1 \
      | awk -F: '{ print $2 }' \
      | sed 's/[",]//g')
    
    echo $PACKAGE_VERSION
    

    Code snippet source