On a current project, I've been creating some Angular libraries to publish to a private artifactory. We wanted to tag our source code builds with the version number, which was in the package.json. How do you do it?
It turns out it isn't that hard to get the version number inside a Jenkins file. This code (Groovy) will do it:
1props = readJSON file: 'package.json'
2 echo props.version
2 echo props.version
Then you just need to use that in your code that creates your tag.
When creating an Angular Library, you have a different package.json for the library in a subdirectory of the main project. You can get that here:
1props = readJSON file: 'projects/lib-name/package.json'
2 echo props.version
2 echo props.version
All works like magic.