I have been trying to migrate our Jenkins setup to AWS EC2. It is supposed to run cypress automation tests but whenever I trigger the jobs I get 504 Gateway timeout error. The app I am testing is also deployed on AWS EC2. So here are a few scenarios I have tested:
-
Installed cypress, Jenkins and app on Host A. Result -> Unable to run cypress from command line and Jenkins
-
Installed cypress and Jenkins on Host B and app on Host A. Result -> I can run cypress from command line on Host B but not from Jenkins.
I can run cypress on my local machine which tests the app on Host A.
Error in both 1 & 2 is the 504 Gateway Timeout error.
I have asked the AWS support person about any restrictions but he isn’t aware of any. I am looking to understand why running cypress is being blocked on AWS when run from the same host as in 1 and why it is not running from Jenkins as in 1 and 2 above? What are the possible restrictions that we can have in the above setup?
Similar setup works fine when everything is on on-premise hosts.
Additional Info I can also use cURL on Host A to connect to the same UI that cypress is unable to connect to.
2
Answers
After looking into multiple things we figured out that it was a proxy configuration issue. I knew from the beginning that it was some external factor other than the configuration of Cypress or Jenkins. Here is a list of things we checked:
all of the above were fine. While tweaking the hosts file Cypress started to throw a different error message:
Cypress could not verify that the server set as your 'baseUrl' is running
This led me to Cypress could not verify that the server set as your 'baseUrl' is running:
One of the answers suggested looking into proxy settings and it turned out that in our .npmrc file we had a proxy configured long time ago but everyone forgot about it and also forgot about the fact that any
npm run
command will make use of that proxy. This also explains why the cURL command was working as it does not use the .npmrc settings config file but npm does.As suggested in the answer, setting NO_PROXY for the app url made it work. I set this environment variable in Jenkins so that our .npmrc can stay the same.
Try adding retries to the test
From How to Fix 504 Gateway Timeout Error: 10 Reliable Solutions
In Cypress, refresh by retrying the test. Also make sure the test is short, if possible.