0

I've defined some scripts in my package.json, e.g.,

    "config": {
    "source": "./assets/stylesheets/civica-styles.scss",
    "dist": "./dist/civica-styles.css",
    "minCss": "./dist/civica-styles.min.css"
  },
  "scripts": {
    "transpile": "cross-var node-sass $npm_package_config_source $npm_package_config_dist",
    "minify": "cross-var cleancss -o $npm_package_config_minCss $npm_package_config_dist"
  }

I can run these at the command line as follows

npm run transpile

I have set up a build in VSTS that performs the following initial tasks:

  1. Get Sources (get my code from the repo)
  2. npm install (installs the packages defined in my package.json)

Now I want to add a task that runs my transpile defined in package.json, so I added the following npm custom task

  • Display name => npm transpile
  • Command => custom
  • Command and arguments => run transpile

However the build fails with

2017-08-01T10:01:42.5125804Z ##[section]Starting: npm custom
2017-08-01T10:01:42.5125804Z ==============================================================================
2017-08-01T10:01:42.5125804Z Task         : npm
2017-08-01T10:01:42.5125804Z Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Package Management.
2017-08-01T10:01:42.5125804Z Version      : 1.0.3
2017-08-01T10:01:42.5125804Z Author       : Microsoft Corporation
2017-08-01T10:01:42.5125804Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613746)
2017-08-01T10:01:42.5125804Z ==============================================================================
2017-08-01T10:01:43.3515881Z ##[error]TypeError: Cannot read property 'trim' of null
2017-08-01T10:01:43.3565858Z ##[section]Finishing: npm custom

Any ideas of how to execute an npm run script from a VSTS build task?

James B
  • 8,975
  • 13
  • 45
  • 83

2 Answers2

0

Check Working folder with package.json box of npm task. It is the folder path not the file, you can use $(Build.SourcesDirectory).

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
0

Running npm from the PowerShell task worked for me.

  1. Set type to "Inline"
  2. Write your task in the "Script" box eg. npm run test
  3. Make sure "Working Directory" is set to the package.json folder under "Advanced"

example

theisof
  • 671
  • 6
  • 6