How can I set environment variable for Proxy in .gitlab-ci.yml file?

Viewed 5270

I am new to GitLab CI. I am trying to run automated tests using selenium in docker containers. I have got the gitlab runner set . I am able to execute a basic test but some of my tests need proxy server. These fail when run in containers.

I tried to add the below in .gitlab-ci.yml file but this doesn't seem to help.

before_script:
  - export HTTP_PROXY="myproxy:port"
  - export HTTPS_PROXY="myproxy:port"

I don't have access to gitlab runner's config.toml file to set the proxy there.

Could you please help on how to set the proxy from .gitlab-ci.yml file ? Also, can I exclude sites which don't need proxy ?Thanks!

1 Answers

You got it right, the proxy environment variables will be available in the script part of the job. If you need to exclude some hosts you can use NO_PROXY.

job1:
  before_script:
    - export HTTP_PROXY="http://myproxy:port"
    - export HTTPS_PROXY="http://myproxy:port"
    - export NO_PROXY=".noproxy.com,.noproxy2.com"
  script:
    - env | grep PROXY

If the environment variables are actually used by your Selenium implementation is other thing, but you have not specified how are you using selenium (Python or Java).

Related