Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you run Jenkins job traffic through a proxy?

I have a Jenkins job that uses a Jenkinsfile and groovy script to do a build.

During the testing/scanning phase I would like to send all traffic through a proxy, specifically right before the groovy script does sh "npm run test".

Is there a way to specify a proxy url and port right before I run the tests so all traffic from that job goes through it?

like image 398
dcblack Avatar asked Dec 13 '22 18:12

dcblack


1 Answers

According to the documentation you can specify HTTP_PROXY environment variable. In Jenkins scripted pipeline you can do it this way

withEnv(['HTTP_PROXY=http://proxyAddress:port']) {
    sh "npm run test"
}

If you use declarative pipeline you need environment { } block

environment { 
    HTTP_PROXY = 'http://proxyAddress:port'
}
like image 117
Vitalii Vitrenko Avatar answered Dec 26 '22 12:12

Vitalii Vitrenko