在詹金斯管道中npm安装失败 [英] npm install fails in Jenkins pipeline

查看:420
本文介绍了在詹金斯管道中npm安装失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个docker映像,以便能够运行节点> = 7.9.0和monogodb在Jenkins中进行测试.有人可能会争辩说,使用mongodb进行测试不是正确的方法,但是该应用程序广泛使用它,并且我进行了一些复杂的更新和删除操作,因此我在那需要它.

I've created a docker images to be able to run node >= 7.9.0 and monogodb for testing in Jenkins. Some might argue that testing with mongodb is not correct approach but the app uses it extensively and I have some complex updates and deletes so I need it there.

Docker文件在我的github存储库中的dockerfiles/test/Dockerfile下.使用管道语法时,docker镜像已成功构建,但是在管道步骤中我无法执行sh'npm install'或sh'npm -v'. docker镜像已经过测试,如果我在本地构建它并运行它,则可以在那里进行npm安装. sh'node -v'在管道中成功运行,也sh'ls'.

Docker file is under dockerfiles/test/Dockerfile in my github repo. When using the pipeline syntax the docker images is built successfully but I can't do sh 'npm install' or sh 'npm -v' in the steps of the pipeline. The docker images is tested and if I build it locally and run it I can do the npm install there. sh 'node -v' runs successfully in the pipeline and also sh 'ls'.

这是管道语法.

pipeline {
  agent { dockerfile { dir 'dockerfiles/test' } }
  stages {
    stage('Build') {
        steps {
           sh 'npm install'
        }
    }
  }
  post {
      always {
        echo 'I will always say Hello again!'
      }
  }
}

我收到此错误:错误:脚本返回了退出代码-1.我看不到这里有什么问题.我还测试了其他具有相同结果的节点图像.如果我使用节点从属服务器运行它,则可以进行安装,但我不想拥有许多具有集成测试设置的不同从属服务器.

I get this error: ERROR: script returned exit code -1. I can't see anything wrong here. I've also tested with other node images with the same result. If I run it with a node slave I can do the installation but I do not want to have many different slaves with a lot of setups for integration tests.

这是dockerfile

And here is the dockerfile

FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
RUN echo "deb http://repo.mongodb.org/apt/ubuntu $(cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2)/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list

RUN apt-get update && apt-get install -y \
curl && \
curl -sL https://deb.nodesource.com/setup_7.x | bash - && \
apt-get install -y nodejs && \
apt-get install -y mongodb-org


RUN mkdir -p /data/db
RUN export LC_ALL=C
RUN groupadd -g 1000 jenkins && useradd -u 1000 jenkins -g jenkins

EXPOSE 27017

CMD ["/usr/bin/mongod"]

推荐答案

找到了解决类似问题的方法.

Found a workaround to a similar problem.

问题

  • Jenkins正在执行管道作业
  • 这项工作正在debian slim容器内运行命令
  • 所有命令立即失败,没有错误输出,只有一个ERROR: script returned exit code -1
  • 在docker外部运行容器并以相同的用户执行相同的命令
  • Jenkins running a pipeline job
  • This job is running commands inside a debian slim container
  • All commands are failing instantly with no error output, only a ERROR: script returned exit code -1
  • Running the container outside docker and executing the same commands with the same user is working as it should be

从Jenkinfile中提取:

Extract from Jenkinfile :

androidImage = docker.build("android")
androidImage.inside('-u root') {
    stage('Install'){
        sh 'npm install' // is failing with generic error and no output
}

解决方案

找到了有关Jenkins bugtracker的答案: https://issues.jenkins-ci. org/browse/JENKINS-35370 Jenkins Docker管道退出代码-1

Found the answer on Jenkins bugtracker : https://issues.jenkins-ci.org/browse/JENKINS-35370 and on Jenkins Docker Pipeline Exit Code -1

通过在我的debian Dockerfile中安装procps软件包解决了我的问题:

My problem was solved by installing the procps package in my debian Dockerfile :

apt-get install -y procps

这篇关于在詹金斯管道中npm安装失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆