Search code examples
.netnode.jsappveyor

Appveyor - .NET MVC and NodeJS build


I have .NET MVC app, that hosts an Angular App.

I need to configure my build yaml with Appveyor to build the .NET solution and also cd into the Angular folder and execute npm install and npm build.

My Appveyor file looks like

# Project configuration
version: $(versionNumber)-{branch}.{build}
# Location of the cloned repo on the build server
clone_folder: c:\projects\something

# Environment Variables
environment: 
  nodejs_version: "8"
  versionNumber: "1.9.0"
  devpackageVersion: "$(versionNumber)-alpha.$(APPVEYOR_BUILD_NUMBER)"
  relpackageVersion: "$(versionNumber).$(APPVEYOR_BUILD_NUMBER)"
  buildFolder: "$(APPVEYOR_BUILD_FOLDER)"

  # Install scripts. (runs after repo cloning)
install:
  # Get the latest stable version of Node.js
  - ps: Install-Product node $env:nodejs_version

# branches to build
branches:
  only:
    - develop
    - /releases.*/
    - /features.*/
    - /bugfixes.*/
    - /hotfixes.*/

# Nuget Restore
nuget:
 # Retrieve packages from account feed
 account_feed: true
 # Retrieve packages from project feed
 project_feed: true

image: Visual Studio 2017

# Build configuration
platform: Any CPU
configuration: Release

# Step to execute before build
before_build:
  # Restore NPM packages
 - ps: cd angular
 - ps: npm install
 - ps: cd ..
  # Restore Nuget packages
 - cmd: nuget restore something.sln -Verbosity quiet

# Step to build the solution
build:
 parallel: true
 # Visual Studio solution to build
 project: something.sln
 verbosity: minimal

# Conditional configuration depending on branch
for:
-
  branches:
    only:
      - develop
      - /features.*/
      - /bugfixes.*/

  # Powershell to pack files for Octopus
  after_build:    
    - ps: octo pack --id=something.something --version="$env:devpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(devpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

# Conditional configuration depending on branch
-
  branches:
    only:
      - /releases.*/
      - /hotfixes.*/

  # Powershell to pack files for Octopus
  after_build:
    - ps: octo pack --id=something.something --version="$env:relpackageVersion" --basePath="$env:buildFolder"\something\ --outFolder="$env:buildFolder"\packages\

  # Step to create the artifact in AppVeyor
  artifacts:
    # Path to the packages created above
    - path: 'packages\*.nupkg'

  # Step to orchestrate Octopus Deploy
  deploy:
    - provider: Octopus
      push_packages: true
      create_release: true
      project: something
      create_release_advanced: --releaseNumber=$(relpackageVersion)
      deploy_release: true
      environment: QA
      server: https://something
      api_key: something
      deploy_wait: false
      push_packages_advanced: --ignoreSslErrors

However this seems to get to the npm install stage and then return 404's or

+ npm install
+ ~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (npm WARN tar EN...2\package.json':String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

I cannot for the life of me work out what is happening.

How can I execute an npm install and npm build, whist also building my .NET solution


Solution

  • If your package.json file is not at the root of your repository then try changing your - ps: npm install script to - ps: npm install ./src/folder1 (where src/folder1 is the folder containing your package.json file relative to the root of your repo).

    If your package.json is at the root of your repository then try moving your - ps: npm install script from the before_build: section to the install: section so that your yml looks like this:

    install:
      - ps: Install-Product node $env:nodejs_version
      - npm install                  #or - npm install ./src/folder1
    

    I had the same issue as you (an appveyor build for a .NET solution hosting an Angular app which required node packages to be installed) and the above worked for me.

    See here for appveyor documentation on NodeJS.