Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Bamboo hanging after trying to run npm test.

I have two tasks that run: one runs 'npm install', the next runs 'npm test'. For some reason, the whole build process hangs after this and I can't be sure why. The output looks like so:

27-Mar-2020 12:03:17
27-Mar-2020 12:03:17 > bambootest@0.1.0 test /home/bytebaron/atlassian-bamboo-7.0.2/xml-data/build-dir/BAM-BTP-JOB1
27-Mar-2020 12:03:17 > react-scripts test
27-Mar-2020 12:03:17
27-Mar-2020 12:03:18 No tests found related to files changed since last commit.27-Mar-2020 12:03:18

1 answer

0 votes

Hi @byte_baron,

Thanks for your inquiry and great to have you here in Community!

Let me start with acquainting some general things about npm. Representing the Node Package Manger, it's bundled with Node.js. Thus once you install Node.js, e.g. from nodejs.org, you can type node -v as well as npm -v on command-line and should see the installed versions of both as an output.

Now prior to use npm, you first need to run command npm init which in turn is creating two essential things, folder node_modules from the directory where you call the command, typically your local Node.js project folder, and file package.json. The latter contains basic information that you entered interactively when running the init and also sections like "scripts" and "dependencies".

It's always a good idea to run whatever you want to run in Bamboo first from outside, so to see that things can really get executed.

That said, within your Node.js project folder you can call npm install moment whereas moment represents a Node.js module containing pretty much everything around elegantly formatting date and time. I could have installed any npm module, of course.

Once that module was installed succeeded, I wrote a simple JS file using the moment module, which could be as simple as this:

var moment = require('moment');
var myDate = new Date();
var myBetterDate = moment(myDate).format("LL");
console.log(myBetterDate);

It merely utilizes the Date method to retrieve the current date from your machine, formats it nicely and prints it out to console.
With that I set up a Bamboo build plan, largely doing what's denoted in section "npm task" and "Node.js task" of the below KB.

Getting started with Node.js and Bamboo 

Note that Bamboo's Server, agent-speficic or shared capability Node.js needs to be set pointing to your Node.js installation. On Linux or MacOS you simply find it by calling which node in a Terminal. Note that this capability is equally used for npm. Besides the environment variable NODE_HOME needs to be set, exactly as the Node.js capability. As the above KB points put, this is where Bamboo primarily looks for the node and npm binaries.

For Bamboo's npm task, the command I use is install moment as it's the moment module that I want to install so to use it in the simple JS script.

Now you say that you see an issue with npm test, not with npm install <module>. The posted build log snippet basically tells us that no tests can be found, like so

27-Mar-2020 12:03:18 No tests found related to files changed since last commit.27-Mar-2020 12:03:18

so it looks like as if you had no tests defined. Is this the case? From your description, it sounds much like your build pipeline is constantly waiting for tests and cannot loop out from there neither finds any.

So how if you'd go and define some e.g. via Mocha or Nodeunit, in the latter case it would be unit tests? Please find the below WEB post providing a great example for use of Mocha (see section "Add mocha" and further).

Testing with NPM 

Looking at my created Node.js environment, also not having had tests, the default package.json file contains this:

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
...

and consequently, I get the following error from outside and from within Bamboo when running there a second npm task with command test

Error: no test specified
npm ERR! Test failed. See above for more details.

and indeed, I do get back a return code of 1.

If I remove the exit 1 part and feed it into the second npm task running command test, I still see the same "Error" message, but no more the "npm ERR!".

In both cases, though, the Bamboo build plan never gets stuck and appears to be hanging. So this part, I fear, I cannot reproduce.

That said, it looks to me like the build apparently not terminating is rather related to your environment and possibly not to Bamboo.

So, what do you see when running npm test outside Bamboo if you run it in exactly the same environment that Bamboo spins up for this plan's working directory?

However, against a build haging forever, you can do something.

Bamboo offers the Hung Build Killer (HBK) option which is to activate and configure as Bamboo Admin under Cog >> Overview >> Build monitoring and there check option "Allow Bamboo to detect hanging builds" and adapt the default values according to your needs, if so.

Kindly see BK Configuring the hanging build event for details.

Please note that within your build you can overwrite the globally set HBK values in your Plan configuration, on job level, per tab Miscellaneous.

Please quote this message with "Accept answer" if it made the trick for you and if not, fell free to share your concerns and further asks per in this thread.

Thanks and and all the best,
Gerhard

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo Data Center is here!

G’day Bamboo customers, The wait is over! Bamboo Data Center edition you have been asking for is finally here! This self-managed enterprise offering of Bamboo has the resilience, reliability, and s...

551 views 1 17
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you