0

My Dockerfile looks something like this.

FROM mhart/alpine-node:8.11.3

RUN mkdir -p /app
COPY ./ /app

WORKDIR /app/build

RUN yarn global add serve
CMD ["serve", "-l", "3000"]

EXPOSE 3000

And then JenkinsFile looks something like this.

 node {
  try {

    stage('Checkout source code') {
        checkout scm
    }

    stage('Install packages') {
      sh("docker run --rm -v `pwd`:/app -w /app node yarn install")
      //sh("sudo chown -R jenkins: ./node_modules")
    }

    stage('Set the enviroment variables') {
      sh("echo set-env-variables")
      }

    stage('Build static assets') {

      sh("docker run --rm -v `pwd`:/app -w /app node yarn build")
    }
  }}

When I do run it on Jenkins,the console output says error Couldn't find a package.json file in "/app" and also it gives an error sudo not found even though I have added Jenkins ALL=(ALL) NOPASSWD: ALL to /etc/sudoers file.

I run the commands listed in my Jenkinsfile on my terminal and they all work fine but when i run them on Jenkins , they dont work.

0

Because you are setting the container's WORKDIR to /app/build so your package.json is not in the working directory, but in the parent of the working directory.

  • But i never build the file using Dockerfile.I am just building the image using docker commands which will copy the entire pwd into app folder in docker container. – Ricky Sterling Nov 14 '18 at 19:53
  • How would you call the process when your docker copies the app folder into the container? What command do you use to achieve it? And what is more important where is your package.json located? – lependu Nov 14 '18 at 19:57
  • docker run --rm -v pwd:/app -w /app node yarn build in this command -v is used fr mounting the volume which says to mount the cwd folder into the /app folder in container process so it kind in a way copies it in /app in container. -w is to change the folder to app in container and execute the command. – Ricky Sterling Nov 15 '18 at 4:56
  • So you have never ran docker build -t [your-image-name] .? Can you please check the working directory in the container (pwd) and the directory content (ls). – lependu Nov 15 '18 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.