Install nodejs in jenkinsfile

87
January 17, 2021, at 07:30 AM

I am trying to install nodejs on jenkins. The first step is to use a dockerfile with node as a base image. Recently, docker started to throttle pulls by anonymous users, so sometimes my image cannot be updated. The fastest way I am trying to do this is by installing nodejs as a stage in my jenkinsfile. I followed the command as illustrated (https://github.com/nodesource/distributions/blob/master/README.md)

# Using Ubuntu
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs

But the error is sudo not found. May I know a better way to install nodejs in jenkins stage. I actually have a docker container in which I am running all my code and hence, it has all the essential packages. So, I do not think I can use plugin. Thanks

Answer 1

If that step in the pipeline is running as root, you don't need sudo. If you're running on regular (non-container) agents, you could install Node ahead of time rather than in the pipeline, which would save you a few seconds on each run. If neither of those work for you, you might find n-install to be handy. Assuming curl, git, and make, this would work: curl -sL https://git.io/n-install | bash -s -- -y (see here for more options).

You could also have your pipeline log in, which would remove the throttling. Assuming you have Docker Hub credentials stored in Jenkins, that would look like:

// empty string meaning the default registry
docker.withRegistry('') {
  // do your work
}
READ ALSO
Android xml design slowing down my application

Android xml design slowing down my application

I have a layout design in my app

88
Passy password generator with boolean parameters

Passy password generator with boolean parameters

Wanted to know the best way to solve thisInput: Will be using the passayPassGenerator and setting the booleans

111
Dashboard Header button and footer button not getting aligned properly in concrete 5

Dashboard Header button and footer button not getting aligned properly in concrete 5

In concrete 5 - Under dashboard pages Header and footer buttons are not getting aligned properlyNeed help

191