如何在jenkins docker容器中安装npm pdf解析库
在jenkins上运行Cypress测试时,我得到以下错误。我们的jenkins与Docker容器集成,开发人员要求我在Docker容器中安装如何在jenkins docker容器中安装npm pdf解析库,docker,jenkins,cypress,docker-container,Docker,Jenkins,Cypress,Docker Container,在jenkins上运行Cypress测试时,我得到以下错误。我们的jenkins与Docker容器集成,开发人员要求我在Docker容器中安装pdf parse库,这将解决这个问题。如何在docker容器中安装pdf parse,哪个文件可以安装?谁能给点建议吗 注意:我无法在我的项目根目录中看到docker文件 11:38:29 Or you might have renamed the extension of your `pluginsFile`. If that's the case,
pdf parse
库,这将解决这个问题。如何在docker容器中安装pdf parse
,哪个文件可以安装?谁能给点建议吗
注意:我无法在我的项目根目录中看到docker文件
11:38:29 Or you might have renamed the extension of your `pluginsFile`. If that's the case, restart the test runner.
11:38:29
11:38:29 Please fix this, or set `pluginsFile` to `false` if a plugins file is not necessary for your project.
11:38:29
11:38:29 Error: Cannot find module 'pdf-parse'
docker文件:
FROM cypress/browsers:node12.14.1-chrome85-ff81
COPY package.json .
COPY package-lock.json .
RUN npm install --save-dev cypress
RUN $(npm bin)/cypress verify
# there is a built-in user "node" that comes from the very base Docker Node image
# we are going to recreate this user and give it _same id_ as external user
# that is going to run this container.
ARG USER_ID=501
ARG GROUP_ID=999
# if you want to see all existing groups uncomment the next command
# RUN cat /etc/group
RUN groupadd -g ${GROUP_ID} appuser
# do not log creating new user, otherwise there could be a lot of messages
RUN useradd -r --no-log-init -u ${USER_ID} -g appuser appuser
RUN install -d -m 0755 -o appuser -g appuser /home/appuser
# move test runner binary folder to the non-root's user home directory
RUN mv /root/.cache /home/appuser/.cache
USER appuser
詹金斯档案:
pipeline {
agent {
docker {
image 'abcdtest'
args '--link postgres:postgres -v /.composer:/.composer'
}
}
options {
ansiColor('xterm')
}
stages {
stage("print env variables") {
steps {
script {
echo sh(script: 'env|sort', returnStdout: true)
}
}
}
stage("composer install") {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'bitbucket-api', passwordVariable: 'bitbucketPassword', usernameVariable: 'bitbucketUsername')]) {
def authProperties = readJSON file: 'auth.json.dist'
authProperties['http-basic']['bitbucket.sometest.com']['username'] = bitbucketUsername
authProperties['http-basic']['bitbucket.sometest.com']['password'] = bitbucketPassword
writeJSON file: 'auth.json', json: authProperties
}
}
sh 'php composer.phar install --prefer-dist --no-progress'
}
}
stage('unit tests') {
steps {
lock('ABCD Unit Tests') {
script {
try {
sh 'mv codeception.yml.dist codeception.yml'
sh 'mv tests/unit.suite.yml.jenkins tests/unit.suite.yml'
sh 'php vendor/bin/codecept run tests/unit --html'
}
catch (err) {
echo "unit tests step failed"
currentBuild.result = 'FAILURE'
}
finally {
publishHTML (target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'tests/_output/',
reportFiles: 'report.html',
reportName: "Unit Tests Report"
])
}
}
}
}
}
}
post {
success {
slackSend color: 'good', channel: '#jenkins-abcdtest-ci', message: "*SUCCESSED* - CI passed successfully for *${env.BRANCH_NAME}* (<${env.BUILD_URL}|build ${env.BUILD_NUMBER}>)"
}
failure {
slackSend color: 'danger', channel: '#jenkins-abcdtest-ci', message: "*FAILED* - CI failed for *${env.BRANCH_NAME}* (<${env.BUILD_URL}|build ${env.BUILD_NUMBER}> - <${env.BUILD_URL}console|click here to see the console output>)"
}
}
}
管道{
代理人{
码头工人{
图像“abcdtest”
args'--link postgres:postgres-v/.composer:/.composer'
}
}
选择权{
ansiColor('xterm')
}
舞台{
阶段(“打印环境变量”){
台阶{
剧本{
echo sh(脚本:“env | sort”,returnStdout:true)
}
}
}
舞台(“作曲家安装”){
台阶{
剧本{
使用凭据([usernamePassword(凭据ID:'bitbucket api',passwordVariable:'bitbucketPassword',usernameVariable:'bitbucketUsername')){
def authProperties=readJSON文件:“auth.json.dist”
authProperties['http-basic']['bitbucket.sometest.com']['username']=bitbucketUsername
authProperties['http-basic']['bitbucket.sometest.com']['password']=bitbucketPassword
writeJSON文件:“auth.json”,json:authProperties
}
}
sh'php composer.phar安装--首选dist--无进展'
}
}
阶段(“单元测试”){
台阶{
锁定('ABCD单元测试'){
剧本{
试一试{
sh'mv codeception.yml.dist codeception.yml'
sh'mv测试/unit.suite.yml.jenkins测试/unit.suite.yml'
sh'php-vendor/bin/codecept-run-tests/unit-html'
}
捕捉(错误){
echo“单元测试步骤失败”
currentBuild.result='失败'
}
最后{
publishHTML(目标:[
allowMissing:false,
alwaysLinkToLastBuild:false,
基帕尔:没错,
reportDir:“测试/_输出/”,
reportFiles:'report.html',
报告名称:“单元测试报告”
])
}
}
}
}
}
}
职位{
成功{
slackSend color:“良好”,频道:“#jenkins abcdtest ci”,消息:“*成功*-成功通过了*${env.BRANCH_NAME}*()的ci”
}
失败{
slackSend颜色:“危险”,通道:“#jenkins abcdtest ci”,消息:“*失败*-ci对*${env.BRANCH_NAME}*()
}
}
}
我想您可以使用cypress/base:10
作为jenkins中新容器的图像。如果没有dockerfile,则可能需要编写自己的dockerfile扩展,扩展自cypress/base:10
Dockerfile:
FROM cypress/base:10
RUN npm install pdf-parse
然后,docker build-t mycypress.
,docker push mycypress
将图像推送到dockerhub(您可能需要一个帐户),让您的jenkins使用您的新图像来设置容器
注意:您必须找到您的项目如何选择image来启动容器,有了它,您可以找到合适的方法来安装pdf parse
。下一个可能是:
pipeline {
agent {
docker { image 'cypress/base:10' }
}
stages {
stage('Test') {
steps {
sh 'node --version'
}
}
}
}
然后,您可以将
docker{image'cypress/base:10'}
更改为docker{image'mycypress'}
抱歉,我最近找到了jenkins文件和docker文件
,所以有一个问题,为什么docker或jenkins不能安装package.json中提到的所有必需的库?在我的例子中,我是否需要在上面的docker文件中添加运行npm install pdf parse
?将解决此问题吗?docker图像
是一个预构建的二进制图像,pdf解析
是一个依赖项,通常,您应该提前在自己的dockerfile中完成。当jenkins运行您的项目时,不要一次又一次地安装它,这会浪费时间。是的,在dockerfile中安装应该可以,但这取决于jenkins如何使用映像,您可以推送到dockerhub,或者您可能有一个本地docker注册表。感谢您的回答和回复,我们将尝试您的解决方案。请原谅我再问一个问题,如果你觉得这很愚蠢,请忽略,。。所以,如果我在上面添加docker文件,当我每次运行时,它会一遍又一遍地安装吗?如果是,我们如何避免这种情况?我认为有两种方法:1)如果你在docker文件中添加安装,并升级你的映像,这里你的是映像'abcdtest'
,那么docker映像的构建就在jenkins之外。您已经提前完成了,因此当jenkins运行时,它不会一次又一次地安装包,您已经在那里有了一个pre-ok环境。2) 如果您在jenkinsstage->step->script->sh
中添加安装,那么您也可以,但是每次启动这个jenkins项目时都会进行安装。