要运行 Cypress,它需要安装系统依赖项,Cypress Dependencies
apt-get install libgtk2.0-0 libgtk-3-0 libnotify-dev
libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
为了在本地 Jenkins 中运行 Cypress 脚本,我正在创建一个 Jenkinsfile
.Jenkinsfile 有一个阶段命令
npx cypress run
在 Jenkins 中,它失败了 "Your system is missing the dependency: Xvfb"
.首先想到的是安装npm package xvfb ,并没有解决问题。
然后,我通过本地Jenkins安装,Jenkins plugin Xvfb ,这奏效了!
我的目标是在远程 Jenkins 上运行 Cypress,但它以同样的方式失败
"Your system is missing the dependency: Xvfb"
.重要提示:我无权访问远程 Jenkins 服务和命令 管理插件 要求安装 Jenkins plugin Xvfb .
由于不清楚如何安装Jenkins plugin Xvfb通过
Jenkinsfile
,我尝试在 Jenkinsfile
内编写 shell 脚本.除了 xvfb
外,每个系统包似乎都安装了,所以这种安装到远程 Jenkins 服务的方法不起作用。sh 'sudo apt-get install libgtk2.0-0 libgtk-3-0
libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
libxtst6 xauth xvfb -y'
有谁知道脚本Jenkinsfile
安装 Jenkins plugin Xvfb在运行 npm 安装之前?谢谢,非常感谢您的帮助
最佳答案
我通过创建一个 docker 文件解决了这个问题,Jenkinsfile 在其中使用了它的图像。 Cypress.io 有自己的 docker 镜像,但它们无法在我组织的 Jenkins 工作环境中工作。这是添加到 Dockerfile 的代码。
我发现使用 Dockerfile 添加 Cypress 依赖项更容易:
# Image installing Cypress Test Runner system dependencies
RUN apt-get update && \
apt-get install --no-install-recommends -y \
# install cypress system dependencies
libgtk2.0-0 \
libgtk-3-0 \
libnotify-dev \
libgconf-2-4 \
libgbm-dev \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
tidy \
xauth \
xvfb \
# clean up
&& rm -rf /var/lib/apt/lists/*
RUN chown jenkins:jenkins -R /home/jenkins
RUN sh -c "echo 'Cypress Build image maintained by Raccoons' >> /build_image.info"
USER jenkins
RUN echo "NODE_VERSION: $NODE_VERSION" \
&& echo "NVM_DIR: $NVM_DIR" \
# NVM install
&& . $NVM_DIR/nvm.sh \
# NPM and Node install
&& nvm install $NODE_VERSION \
# cypress install
echo "CYPRESS_VERSION: $CYPRESS_VERSION" \
&& npm install -g cypress@$CYPRESS_VERSION \
&& cypress verify \
&& cypress info
关于jenkins - Cypress 和 Jenkins : Install system dependency "xvfb" via Jenkinsfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63293440/