Continuous integration and deployment of Node.js application on Bamboo - node.js

The application I want to implement continuous deployment on Bamboo has node modules and bower component dependencies. On the bamboo server nodejs, npm have been installed.
There are only three tasks on default job:
Source Code Checkout
Build dependencies:
npm install
bower install
Deploy to the staging server
The problem is on the second task, bamboo fails with the message "No failed tests found, a possible compilation error occurred." I don't even run any tests.
The log file is not explanatory at all:
Starting task 'Build dependencies' of type 'com.atlassian.bamboo.plugins.scripttask:task.builder.script'
Failing task since return code of [/bin/sh /home/ubuntu/bamboo-installation/temp/WEB-WEB-JOB1-8-ScriptBuildTask-4430338079602360707.sh] was 1 while expected 0

Ok, I solved the problem. The issue was the wrong node (which obviously messed things up) was installed on the bamboo server. Uninstalled the wrong one and everything worked as expected.

Good to see you solved it.
There is a setup I use and which could prevent further problems with CI:
export npm_config_prefix=.npm/
export PATH=.npm/bin:$PATH
export CI=true
npm install -g bower
bower install
npm install
This installs bower (and others like grunt-cli if you want) in your project folder so you can e.g. have a specific version, sets CI=true as advised in bower docs, and then installs all dependencies.

Bamboo AMI originally have npm version 1.4.28 installed and you are probably using a more recent version on you development environment. I had the same issue and resolved it by creating a script task to update npm version on the very beginning of my build process. Here is the script:
# update npm
curl -O -L https://npmjs.org/install.sh
chmod +x install.sh
sudo PATH=$PATH:/opt/node-0.10/bin ./install.sh

Related

Which script am I missing when trying to install framework7 custom build?

npm ERR! missing script: build-core:prod
I'm receiving the above error when trying to run the custom build for framework7 - https://framework7.io/docs/custom-build.html
I have gone through each step however I am running into this problem in cmder and I'm unsure why.
The error occurs at step 7 if this info is of any value
Any help would be appreicated.
The error says it cannot find the script build-core:prod.
I could replicate this error (missing build-core:prod), by NOT INSTALLING THE DEPENDENCIES after cloning from github.
So the steps are:
1. Clone the Framework7 Github repository
git clone https://github.com/framework7io/framework7 my-app
this will download the repository in a folder called my-app
2. Install Node.js
that's another topic, hope you have that installed
3. Install Gulp
npm install --global gulp
if you don't have that
4. Install dependencies
cd my-app
npm install
be sure that you are in the root of my-app (the directory you just created for the cloned repository)
this installs all the dependencies that Framework7 Custom Build needs
5. Duplicate my-app/scripts/build-config.js
and rename the duplicate to my-app/scripts/my-config.js
6. Open my-config.js and edit it as you need
7. Go to my-app folder (the root)
and run
npm run build-core:prod -- --config scripts/my-config.js --output path/to/output/folder
path/to/output/folder is a path to the folder where you want the customised files to be, it can be (for example) f7-my-custom-build
8. The custom build is ready,
hopefully you can work with it now. :)

Grunt --force fails with node: bad option

I have a Grunt task called eslint:jenkins that runs eslint on the project. In the build pipeline I run it as:
grunt eslint:jenkins --force --verbose
I use --force so the grunt will not fail even if the task fails because there are some eslint issues.
When I run this locally everything is fine. When this runs on Jenkins I get the following error:
<path-to-installation>/Node_10/bin/node: bad option: --force
For both local and Jenkins environments the versions are: Node 10.0 and grunt-cli 1.3.1.
I cannot imagine any reason why in one case the --force flag is propagated to Node. Can anybody give me some pointers on where to look at?
Same issue with node 10 and a gulp task with arguments.
./node_modules/.bin/gulp tasks:my-task --myoption=value
[16:14:24] Node flags detected: --myoption=value
[16:14:24] Respawned to PID: 21231
No issue with node 8. Did not try with node 9. There must have been a breaking change somewhere, but I can find any information on this beside this question and https://github.com/gulpjs/gulp/issues/1564
sudo npm install grunt-cli -g
Should output something like:
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli#1.3.2
updated 2 packages in 3.056s
Then grunt --force should work for you.
(Tested on macOS Mojave)
Try using
grunt tasks:my-task -myoption=value, it worked for me.

'npm EER! code 1' When installing dependencies using `npm install --production`

I am using flightplan to deploy my node.js application to my server. I run the command fly production in my CLI to deploy my app to the server. It does rsync fine, but when it comes to installing dependencies, I get the following error:
I made sure that I have sudo privileges on my server for this user and npm is definitely installed as it gives the version number when I run the command npm -von my server. I have tried to run npm install --production myself on the server as the deploy script does and I get the same error, meaning it is something to do with installing dependencies. Potentially, it could be because in my flightplan.js, when it runs the command git ls-files to get the files to copy across. it includes all the node_modules even though i've made sure that node_modules is in the .gitingore file.
Does anyone have experience with flightplan npm module/or know why my npm install isn't working on my server?
(I edited out my server IP address from the picture)
Thanks in advance!
I found that if I removed the node_modules folder by running command rm -rf node_modules/ then committed this to github, then re-ran npm install and then my call to fly production worked successfully.

wedriverio jenkins - npm command not found error

I am trying to run webdriverio test from jenkins and following this . I installed nodeJS plugin for jenkins and under global tool config, for NodeJS , added a name and installation directory as /usr/local/bin (node executable is in this folder)
In Jenkins, in project config , under build environment, I have checked
Provide Node & npm bin/ folder to PATH and chosen the node installation name from previous step
But when I am trying to run npm install
npm test ,by adding these commands under execute shell under Build and building it, I receive this error
Building in workspace /Users/Shared/Jenkins/Home/workspace/wdio-project
[wdio-project] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh
+ npm install
/Users/Shared/Jenkins/tmp/hudson1478028169114509075.sh: line 2: npm: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
In case someone is looking for same issue, I resolved the above error by adding export PATH=/usr/local/bin to the execute shell under build. This post helped me
There is currently a bug opened about this (JENKINS-26583 and JENKINS-27170)
I could workaround this bug by adding explicitly node on the PATH by adding this line :
export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/
I had just fixed the same issue as you did.
I wonder if my fix would also help you. When I was using the alpine-based docker image, the Jenkins can never find the npm, but when I use the debian-based docker image, problem solved immediately.
Try this export PATH=/usr/local/bin:$PATH
After installation of NodeJS restart pc
In my case this worked -
export PATH=$PATH:/usr/local/bin

Jenkins script quitting prematurely when using npm install on Windows

In my Jenkins job I want to build a JavaScript app using Grunt. The Jenkins build scripts creates a build directory (if it doesn't already exist), changes to that directory and runs:
npm install grunt
npm install grunt-zip
grunt --gruntfile=[something]
(Of course grunt-cli is installed globally.) When I build the job, the first statement causes Grunt and dependencies to be pulled down as expected. However, the job then terminates successfully:
Archiving artifacts
No emails were triggered.
Finished: SUCCESS
The second npm install is not run. Any idea why the script is terminating after running npm install instead of continuing to the subsequent statements?
So it turns out that npm is a batch file, not an executable, so it needs to be invoked using call from the Jenkins script:
call npm install grunt
i would recommend not using the local grunt / nodejs install, but instead getting jenkins to do this for you!
it's much easier and means there's less coupling to system specific installs and variables.
steps:
a) use nodejs jenkins plugin + get it to install nodejs on machine/grunt-cli -> Jenkins integration with Grunt
b) populate your package.json with any nodejs dependances required, eg grunt/grunt-zip etc
c) when running grunt just do a "npm update" before "grunt" command
that way your not doing explicit npm install, it's all configured from your package.json, and your build scripts will be less brittle, and your developers can use the same steps as the build server, eg "npm update;grunt" locally same as build server
For future googlers:
use command chaining for this.
This works:
npm install && npm install install grunt-zip
This wont work:
npm install
npm install grunt-zip

Resources