Getting version from package.json
I'm using appveyor to build a node app. Some of the artifacts produced have the version number (specified in my package.json file) in their name. So I'd like to be able to get the version number out of the package.json file into a environment variable. I know I could write some powershell without too much trouble, but I was wondering if there was a first class way of doing this? Does appveyor understand package.json?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Feodor Fitsner on 08 Dec, 2015 05:49 PM
It's not supported out-of-the-box, so PowerShell is your option :)
2 Posted by kneumei on 08 Dec, 2015 05:52 PM
Thanks. For anyone coming along later, you can do it like this:
3 Posted by Kosmas Papadato... on 11 Jan, 2017 09:49 AM
Tried this but didn't work:
init:
- git config --global core.autocrlf true
- ps: $env:package_version = (Get-Content -Raw -Path package.json | ConvertFrom-Json).version
version: $(package_version)-{build}
4 Posted by Ilya Finkelshte... on 11 Jan, 2017 05:25 PM
Hi Kosmas,
init
scrips happens before clone, thereforepackage.json
is not available at that moment. Also you have to update build details with API, if you need to do it during the build. Please try the following atinstall
stage:Let us know if this helps.
--ilya.
5 Posted by Kosmas Papadato... on 12 Jan, 2017 08:48 AM
It had to be $env:package_version isntead of $(package_version), thanks!
install:
- ps: $env:package_version = (Get-Content -Raw -Path package.json | ConvertFrom-Json).version
- ps: Update-AppveyorBuild -Version "$env:package_version-$env:APPVEYOR_BUILD_NUMBER"
6 Posted by Ilya Finkelshte... on 12 Jan, 2017 09:18 AM
Oh, sure you are right :)
7 Posted by joelb on 30 Mar, 2018 12:24 AM
So, based on the above I have the following line in the 'Install script' section of the Environment configuration page:
PowerShell (Get-Content -Raw -Path package.json | ConvertFrom-JSON).version
I'm getting an error stating "'ConvertFrom-JSON' is not recognized as an internal or external command".
I've confirmed that we're using PS v5.
What am I missing?
Thanks
8 Posted by Ilya Finkelshte... on 30 Mar, 2018 01:59 AM
@joelb please share your configuration in YAML format.
9 Posted by joelb on 30 Mar, 2018 02:03 AM
version: 1.0.{build}
branches:
only:
- master
init:
- cmd: PowerShell Install-Product node 7.2.1
install:
- cmd: "PowerShell $env:package_version = (Get-Content -Raw -Path package.json | ConvertFrom-JSON).version \necho %$env:package_version%\n\nUpdate-AppveyorBuild -Version \"$($env.package_version)\"\n\nnpm install"
build_script:
- cmd: >-
set NODE_ENV=development
npm run build
7z a nexus-client-dev.zip @deploy-package.txt
test: off
artifacts:
- path: nexus-client-dev.zip
name: nexus-client-dev
Above is the exported yaml.
Thanks
From: Ilya Finkelshteyn [***@***]
Sent: Thursday, March 29, 2018 6:59 PM
To: Joel Brighton
Subject: Re: Getting version from package.json [Questions #1954]
// Please reply above this line
==================================================
From: Ilya Finkelshteyn (Support staff)
@joelb please share your configuration in YAML format.
On Thu, Mar 29 at 05:24 PM PDT, joelb wrote:
Having trouble reading this? View this discussion online:
10 Posted by Ilya Finkelshte... on 30 Mar, 2018 06:27 PM
If you run
PowerShell (Get-Content -Raw -Path package.json | ConvertFrom-JSON).version
on your local Windows machine in command prompt, you will get the same result. If you runPowerShell "(Get-Content -Raw -Path package.json | ConvertFrom-JSON).version"
(see quotes added), you will get expected results (provided you havepackage.json
in the current directory.Additional notes:
%%
will work, it isCMD
environment variable notation, notPowerShell
CMD
mode at all. It can be easily called inPS
mode without callingPowerShell
explicitly, as in previous examples in this thread.Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:27 AM.