2

I am setting up a Jenkins build pipeline for vue application. I have a simple Dockerfile to build&run VUE application as a container. When I am trying to build the application on my PC, docker build successfully finishes without an error.

However once the Jenkins build process is started, RUN npm install command of the Dockerfile returns an error while the build stage is in process.

I checked the server's swap space, the error is not related to that. Manually, I executed a npm install file for the package.json file on server.

Does anybody have an experience regarding to executing npm commands during Jenkins pipeline stage?

Here is the both Dockerfile & Jenkinsfile that I used

Dockerfile

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Jenkinsfile

#!/usr/bin/env groovy

pipeline {
    options {
        timeout(time: 1, unit: 'HOURS')
    }

    agent none

    stages {
        stage('Pre process') {
            agent any
            steps {
                script {
                    ...
                }       
                ...               
            }
        }
        stage('Build') {
            agent any
            steps {
                sh 'docker build -t frontend'
            }
        }
        stage('Run') {
            agent any
            steps {
                sh 'docker run ..... '
            }
        }
        stage('Update') {
            agent any
            steps {
                e..
            }
        }
        stage('Test & Clean-up') {
            ....
        }
    } // stages
} // pipeline

Error message

Step 4/10 : RUN npm install

 ---> Running in 80e0beb9442a



> [email protected] install /app/node_modules/node-sass

> node scripts/install.js





Service 'frontend' failed to build: The command '/bin/sh -c npm install' returned a non-zero code: 1

script returned exit code 1

1 Answer 1

2

The difference could be because you don't have the exact node image version in your Dockerfile. It could be different on your PC and on server. Try changing that to some fixed version, like node:10.15.1-alpine.

Also temporarily try docker build with --no-cache option to avoid any problems caused by layers of cache.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a ton you saved my day. I changed to base image to node:8.11.3-alpine. Also added --no-cache option for docker-compose build.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.