首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在jenkins docker容器中安装npm解析库?

如何在jenkins docker容器中安装npm解析库?
EN

Stack Overflow用户
提问于 2021-06-08 00:57:45
回答 1查看 143关注 0票数 1

在jenkins上运行Cypress测试时,我得到了以下错误。我们的jenkins与Docker容器集成,devs要求我在码头容器中安装pdf-parse库,这将解决这个问题。如何在码头容器中安装pdf-parse,哪个文件是这样做的?能给我个建议吗?

注意:我无法在我的项目根目录中看到docker文件。

代码语言:javascript
复制
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'

码头档案:

代码语言:javascript
复制
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

jenkins档案:

代码语言:javascript
复制
 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>)"
        }
      }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-08 02:25:06

我想您应该使用cypress/base:10作为图像,在jenkins中新建一个容器。如果您没有dockerfile,您可能必须编写您自己的从cypress/base:10扩展的dockerfile。

文档:

代码语言:javascript
复制
FROM cypress/base:10
RUN npm install pdf-parse

然后,docker build -t mycypress .docker push mycypress将映像推送到dockerhub(您可能需要一个帐户),以便让jenkins使用您的新映像来设置容器。

注意:您必须找到项目如何选择映像来启动容器,这样,您就可以找到安装pdf-parse的合适方法。其中一个可能是下一个:

代码语言:javascript
复制
pipeline {
    agent {
        docker { image 'cypress/base:10' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

然后,您可以将docker { image 'cypress/base:10' }更改为docker { image 'mycypress' }

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67880200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档