kalpitha
kalpitha

Reputation: 41

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

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!

Upvotes: 3

Views: 14092

Answers (2)

Mathesh
Mathesh

Reputation: 81

Add variables in your yml file. variable declartion will take care of PROXY.

EX:

stages:  
- build

variables:
    HTTP_PROXY: "$CODE_PROXY"
    HTTPS_PROXY: "$CODE_PROXY"
    no_proxy: "$CODE_NO_PROXY"

Upvotes: 1

balonik
balonik

Reputation: 331

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).

Upvotes: 3

Related Questions