jenkins - 使用 Jenkins 运行 cypress 时缺少 package.json
问题描述
我一直在尝试遵循 cypress在此处为 Jenkins 提供的 CI 设置示例。
我正在使用以下 Jenkins 管道脚本(也由赛普拉斯的好人提供):
// Example Jenkins pipeline with Cypress end-to-end tests running in parallel on 2 workers
// Pipeline syntax from https://jenkins.io/doc/book/pipeline/
// Setup:
// before starting Jenkins, I have created several volumes to cache
// Jenkins configuration, NPM modules and Cypress binary
// docker volume create jenkins-data
// docker volume create npm-cache
// docker volume create cypress-cache
// Start Jenkins command line by line:
// - run as "root" user (insecure, contact your admin to configure user and groups!)
// - run Docker in disconnected mode
// - name running container "blue-ocean"
// - map port 8080 with Jenkins UI
// - map volumes for Jenkins data, NPM and Cypress caches
// - pass Docker socket which allows Jenkins to start worker containers
// - download and execute the latest BlueOcean Docker image
// docker run \
// -u root \
// -d \
// --name blue-ocean \
// -p 8080:8080 \
// -v jenkins-data:/var/jenkins_home \
// -v npm-cache:/root/.npm \
// -v cypress-cache:/root/.cache \
// -v /var/run/docker.sock:/var/run/docker.sock \
// jenkinsci/blueocean:latest
// If you start for the very first time, inspect the logs from the running container
// to see Administrator password - you will need it to configure Jenkins via localhost:8080 UI
// docker logs blue-ocean
pipeline {
agent {
// this image provides everything needed to run Cypress
docker {
image 'cypress/base:10'
}
}
stages {
// first stage installs node dependencies and Cypress binary
stage('build') {
steps {
// there a few default environment variables on Jenkins
// on local Jenkins machine (assuming port 8080) see
// http://localhost:8080/pipeline-syntax/globals#env
echo "Running build ${env.BUILD_ID} on ${env.JENKINS_URL}"
sh 'npm ci'
sh 'npm run cy:verify'
}
}
stage('start local server') {
steps {
// start local server in the background
// we will shut it down in "post" command block
sh 'nohup npm start &'
}
}
// this tage runs end-to-end tests, and each agent uses the workspace
// from the previous stage
stage('cypress parallel tests') {
environment {
// we will be recordint test results and video on Cypress dashboard
// to record we need to set an environment variable
// we can load the record key variable from credentials store
// see https://jenkins.io/doc/book/using/using-credentials/
CYPRESS_RECORD_KEY = credentials('cypress-example-kitchensink-record-key')
// because parallel steps share the workspace they might race to delete
// screenshots and videos folders. Tell Cypress not to delete these folders
CYPRESS_trashAssetsBeforeRuns = 'false'
}
// https://jenkins.io/doc/book/pipeline/syntax/#parallel
parallel {
// start several test jobs in parallel, and they all
// will use Cypress Dashboard to load balance any found spec files
stage('tester A') {
steps {
echo "Running build ${env.BUILD_ID}"
sh "npm run e2e:record:parallel"
}
}
// second tester runs the same command
stage('tester B') {
steps {
echo "Running build ${env.BUILD_ID}"
sh "npm run e2e:record:parallel"
}
}
}
}
}
post {
// shutdown the server running in the background
always {
echo 'Stopping local server'
sh 'pkill -f http-server'
}
}
}
我正在使用“触发器远程构建”构建触发器。当我执行该 URL 时,第一步(下载最新的蓝海 docker 映像)似乎可以成功运行。
但是,当 npm 尝试启动 package.json 时,它似乎找不到它。我的 Jenkins 控制台日志的图像在这里和这里。我注意到为什么 package.json 文件不存在?我应该从厨房水槽回购中添加它吗?不知何故?
非常感谢任何提示。
解决方案
推荐阅读
- matlab - 在 Matlab 上找到一个交点
- c# - C# Solr 查询,Boost 不起作用
- apache-flink - 为什么上次匹配事件的摄取时间和 CEP 匹配并触发模式的时间之间的时间如此之长?
- reactjs - react-virtualized Masonry 服务器渲染输出与客户端渲染不匹配
- google-analytics - 使用 Google Analytics 跟踪虚拟综合浏览量时,主(根)路径的正确路径名是什么?
- c++ - 无法使用 C++ 代码对 MongoDB 进行身份验证
- css - Vuetify 图标不在按钮内居中
- ios - 'touchIDLockout' 在 iOS 11.0 中被弃用:使用 LAErrorBiometryLockout
- azure - Azure WAF 流量
- mysql - 我们可以在不读取文件的情况下使用 pandas 执行删除操作吗