I'm using the below to pull the version from my package.json file and set it to one of my build variables, Version.
# successfully retrieves and prints the version to console
ver=$(node -e "console.log(require('./package.json').version)")
echo "Version: $ver"
# does jack squat
# even trying to hard-code something in place of $ver doesn't set the variable
echo "##vso[task.setvariable variable=Version]$ver"
echo "Version: $(Version)"
I've tried using ver and $(ver) instead of $ver, none work as the console prints a blank for $(Version) in all cases (it's empty to begin with). If I hard-code Version, it prints fine, so it's not the printing or the retrieving, it's the setting that's the issue. I've based my script on MS' example,
echo "##vso[task.setvariable variable=sauce]crushed tomatoes"
Our build server is in a Windows environment.