Nodejs's image URL: https://npm.taobao.org/mirrors/node/latest-v6.x/
First, install the Nodejs
Download nodes, and install:
# cd /app/service_tools/# wget https://npm.taobao.org/mirrors/node/v9.3.0/node-v9.3.0-linux-x64.tar.xz# xz -d node-v9.3.0-linux-x64.tar.xz# tar xf node-v9.3.0-linux-x64.tar# ln -s /app/service_tools/node-v9.3.0-linux-x64 /app/service_tools/node-v9.3.0# ln -s /app/service_tools/node-v9.3.0/bin/node /usr/bin/node# ln -s /app/service_tools/node-v9.3.0/bin/npm /usr/bin/npm如果可以查看到版本号证明安装成功:[[email protected] ~]# node -vv9.3.0[[email protected] ~]# npm -v5.5.1
Sometimes an error occurs when compiling a front-end project via NPM:
npm ERR! path /app/Jenkins/.jenkins/workspace/test-marketweb-second/package.jsonnpm ERR! code ENOENTnpm ERR! errno -2npm ERR! syscall opennpm ERR! enoent ENOENT: no such file or directory, open ‘/app/Jenkins/.jenkins/workspace/test-marketweb-second/package.json‘npm ERR! enoent This is related to npm not being able to find a file.npm ERR! enoent npm ERR! A complete log of this run can be found in:npm ERR! /root/.npm/_logs/2018-06-12T09_51_48_611Z-debug.logBuild step ‘Execute shell‘ marked build as failureSSH: Current build result is [FAILURE], not going to run.Finished: FAILURE
When you encounter this problem, you can try to install the CNPM command and Webpack:
# npm install -g cnpm --registry=https://registry.npm.taobao.org# ln -s /app/service_tools/node-v9.3.0/bin/cnpm /usr/bin/cnpm# cnpm install webpack -g
Jenkins configuration:
In System Management, Global Tool Configuration, set the installation method for Nodejs, or install the path:
First, new project selection "Building a free-style software project"
Second, the project configuration
Setting up the environment for the node environment in the build environment
Build command:
Jenkins + Nodejs compiling packaged Nodejs application