问题
I have seen this on github but I was still not able to get cypress
to configure/download correctly. In my jenkins pipeline I run npm install
but this runs into a timeout because of the proxy. It downloads all other dependencies expect cypress
.
What I did was download cypress
and put the zip file in the project. I then run sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress"
but this still fails.
Part that fails in Jenkins pipeline:
sh "npm config set proxy http://<proxy>"
sh "npm config set registry http://<proxy>/"
sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress"
sh "npm i"
sh "npm run build
How can I have npm i
run without download cypress. I currently cannot get passed this line sh "setCYPRESS_INSTALL_BINARY=cypress.zip npm i cypress"
but I am also concerned npm i
will still try to download cypress after setCYPRESS_INSTALL_BINARY
actually works
-------------------------Update One-----------------
I updated the Jenkinsfile
to have CYPRESS_INSTALL_BINARY=cypress.zip npm i
but now I get the below error. Cypress.zip
is in the project now but would really like to have it uploaded to Jenkins and just reference the file path within my Jenkinsfile.
I am not sure that is possible and the most simple solution is the one I am doing I think however it fails.
New error:
[view] Running shell script
+ CYPRESS_INSTALL_BINARY=cypress.zip
+ npm install
npm WARN locking Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock failed { Error: EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
npm WARN locking stack: 'Error: EIO: i/o error, open \'/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock\'',
npm WARN locking errno: -5,
npm WARN locking code: 'EIO',
npm WARN locking syscall: 'open',
npm WARN locking path: '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock' }
npm ERR! path /home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock
npm ERR! code EIO
npm ERR! errno -5
npm ERR! syscall open
npm ERR! EIO: i/o error, open '/home/jenkins/.npm/_locks/staging-c21b8f081f002623.lock'
script returned exit code 251
回答1:
I had similar issues on Windows environment. I placed cypress.zip into project's root folder.
set CYPRESS_INSTALL_BINARY=cypress.zip
echo %CYPRESS_INSTALL_BINARY%
npm install cypress --save-dev
So installation did not work, because npm executable looks for cypress in <your project folder>\node_modules\cypress\
Try to set CYPRESS_INSTALL_BINARY to absolute path.
回答2:
I'm assuming you're on linux, so the way to set an environment variable
is CYPRESS_INSTALL_BINARY='cypress.zip'
("set "
is only used on Windows)
Cypress will not try to download the binary if it's found on the system, even when running npm install
again. By default Cypress downloads the binary to ~/.cache/Cypress
, so on subsequent builds Cypress will not have to extract the zip if this directory persists between builds.
The following should work:
CYPRESS_INSTALL_BINARY='cypress.zip` npm install
no need to explicitly run npm install cypress
Then, ensure the ~/.cache
directory is saved after and restored before npm install
across builds.
or
Pre-extract the cypress.zip onto the build system to /Cypress
, and use the following:
CYPRESS_INSTALL_BINARY=0 npm install ## Don't install the binary!
CYPRESS_RUN_BINARY='Cypress/Cypress' ## this is the Cypress executable!
again, make sure /Cypress
persists across builds
What if I don't cache ~/.cache
?
Well, your build will still run, but take significantly longer as Cypress will have to extract its binary on every build. Read more here about caching the binary in CI
...
Edit: For Question Update
You're still not setting environment variables correctly. This will not work:
CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
You need to do:
CYPRESS_INSTALL_BINARY='cypress.zip' npm install
In one line.
or
export CYPRESS_INSTALL_BINARY='cypress.zip'
npm install
-> Why here
回答3:
I created a tool to deal with this problem: https://github.com/tomasbjerre/dictator-cypress-example
You would need to clone this repository and publish your own cypress-dictator
to your private npm repository:
https://github.com/tomasbjerre/dictator-cypress
It uses dictator builder to, before npm install
, copy platform specific zip-files to root of repository and make sure it is pointed at by .npmrc
.
{
"message": "Copy linux cypress to cypress.zip",
"triggers": [
{
"runningOnPlatform": ["linux"]
}
],
"actions": [
{
"copyFrom": "linux-x64.zip",
"target": "cypress.zip"
}
]
}
来源:https://stackoverflow.com/questions/50820360/using-cypress-behind-proxy-in-jenkins-pipeline