User Agents

Web browsers and everyday web tech, explained

Configure Chrome Bin in Jenkins for Headless Chrome

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Configuring the Chrome binary path in Jenkins allows your automated test suites—such as those using Selenium, Puppeteer, or Playwright—to locate and launch the Google Chrome browser in a headless environment. Headless mode runs the browser without a graphical user interface, which is essential for CI/CD pipelines running on Linux servers where no monitor is attached. By explicitly defining the Chrome binary location in the Jenkins environment or tool configuration, you eliminate "browser not found" errors and ensure consistent execution across different build nodes.

What You'll Need

  • A Jenkins server with administrative access.
  • Google Chrome or Chromium installed on the Jenkins agent/node where the tests will run.
  • Sudo or root privileges on the agent machine to verify installation paths.
  • A testing framework (e.g., Selenium WebDriver, Cypress) configured to accept a binary path.

Step-by-Step

  1. Locate the Chrome Binary Path: Log into the server or agent where the tests will execute. Run the command which google-chrome (for stable Chrome) or which chromium-browser (for Chromium). Note the full path returned, such as /usr/bin/google-chrome.
  2. Install Chrome on the Agent: If the previous step returned nothing, install Chrome. On Ubuntu/Debian, use: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb followed by sudo apt install ./google-chrome-stable_current_amd64.deb.
  3. Configure Jenkins Global Tool Configuration: Navigate to Manage Jenkins > Global Tool Configuration. While Jenkins doesn't have a native "Chrome" tool section, you can define the path here if you use a specific plugin, or more commonly, move to the environment variables section.
  4. Set Environment Variables for the Node: Go to Manage Jenkins > Nodes. Select the specific node (or 'Built-in Node') and click Configure. Under Node Properties, check the box for Environment variables.
  5. Define the CHROME_BIN Variable: Click Add. Set the Key to CHROME_BIN and the Value to the path you found in Step 1 (e.g., /usr/bin/google-chrome). This makes the path available to any script or tool running on that node.
  6. Update Your Test Code for Headless Mode: The binary path tells Jenkins where Chrome is, but your code tells Chrome how to run. In your Selenium/WebDriver configuration, add the following arguments: --headless, --no-sandbox, and --disable-dev-shm-usage.
  7. Verify the Configuration: Create a simple Jenkins pipeline job to test the path. Use a shell script step: echo $CHROME_BIN && $CHROME_BIN --version. If the version number prints in the console output, the configuration is successful.

Common Mistakes

  • Forgetting the --no-sandbox Flag: Chrome's sandbox requires a user namespace that is often restricted in Docker containers or Jenkins agents. Failing to add --no-sandbox often results in the browser crashing immediately on startup.
  • Assuming Path Consistency: Using a hardcoded path like /usr/bin/google-chrome in your code instead of using the CHROME_BIN environment variable. This causes builds to fail when moving from a Linux agent to a macOS or Windows agent.
  • Permission Issues: Installing Chrome as a root user but running the Jenkins agent as a jenkins user, leading to "Permission Denied" errors when attempting to execute the binary.
  • Version Mismatch: Using a ChromeDriver version that does not match the installed Chrome binary version. Always ensure the driver and the browser are synchronized.

Tips

  • Use Dockerized Agents: Instead of installing Chrome directly on the host, use a Docker image that comes pre-installed with Chrome and ChromeDriver. This ensures the binary path is identical every time.
  • Disable Shared Memory: Always use --disable-dev-shm-usage in headless mode. This forces Chrome to use /tmp instead of /dev/shm, preventing crashes in resource-constrained environments like Kubernetes pods.
  • Log Browser Output: When debugging, redirect Chrome's stdout and stderr to a file in your Jenkins workspace to capture the exact reason for a browser crash.

Troubleshooting

If your tests still fail with "SessionNotCreatedException" or "WebDriverException: unknown error: cannot find Chrome binary", check the following:

  • Verify Path Existence: Run ls -l /usr/bin/google-chrome on the agent. If the file is missing, the installation failed or the path is different.
  • Check Dependencies: Chrome requires several X11 and system libraries even in headless mode. Run ldd /usr/bin/google-chrome to see if any shared libraries are listed as "not found". Install missing libraries via apt-get.
  • Zombie Processes: Sometimes crashed headless instances stay alive and lock profiles. Use pkill chrome or killall chrome in a pre-build step to clear the environment.
  • Check Jenkins User Permissions: Ensure the jenkins user has execution permissions for the binary. Use chmod +x /usr/bin/google-chrome if necessary.

Frequently Asked Questions

Do I need a GUI installed on the Jenkins server?

No. Headless Chrome is designed specifically to run without a display server (like X11 or Wayland). As long as the necessary system libraries are installed, it will function on a CLI-only server.

What is the difference between CHROME_BIN and chromedriver?

CHROME_BIN refers to the actual browser executable that renders pages. chromedriver is a separate bridge tool that allows your test scripts (Java, Python, JS) to communicate with the browser.

Can I use different Chrome versions for different jobs?

Yes. You can install multiple versions of Chrome in different directories and set a job-specific environment variable for CHROME_BIN in the project configuration, overriding the global node setting.

Why is my headless Chrome using so much memory?

Chrome is resource-intensive. Using the --disable-dev-shm-usage flag and limiting the number of parallel browser instances in your test runner can help stabilize memory usage.

Does this configuration work for Chromium?

Yes. Chromium is the open-source base for Chrome. Simply point the CHROME_BIN variable to the Chromium executable path (usually /usr/bin/chromium-browser).