ng not found error while docker build in jenkins pipeline (script)

Issue found on npm while docker build: hicare_omdashboard_prod

The issue is simple, npm doesn't know about ng.

I got the following issue while docker build:

From the logs shell script, I found:

> store-web@0.0.0 build /App
> ng build

sh: 1: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! store-web@0.0.0 build: `ng build`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the store-web@0.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2024-02-27T09_13_42_130Z-debug.log
The command '/bin/sh -c npm run build --prod' returned a non-zero code: 1
  1. Then, I looking for Dockerfile.

  • Status -> Workspace -> given link

In my case,

Workspaces for OM Dashboard Angular Pipeline(S3 Prod) Docker-ECR #95

  1. Check the Dockerfile.

I found:

FROM node:14.16.1 as source
WORKDIR /App
COPY /package.json .
RUN npm install
COPY /. .
RUN npm run build --prod

FROM nginx:alpine
COPY --from=source /App/dist/StoreWeb /usr/share/nginx/html
EXPOSE 80

Then, I tried to install angular/cli with dockerfile. But I ask for version 18.0.2.

FROM node:14.16.1 as source
WORKDIR /App
COPY /package.json .

RUN npm install -g @angular/cli@latest
RUN npm install
COPY /. .
RUN npm run build --prod

FROM nginx:alpine
COPY --from=source /App/dist/StoreWeb /usr/share/nginx/html
EXPOSE 80

Later, I installed the angular/cli in cli instead of dockerfile: Install in the jenkins server cli:

npm install -g @angular/cli@latest

Issue is finally solved. 🎉

Last updated