Search code examples
javaproxyhudsonhudson-plugins

Can I access Hudson's plugin proxy settings from within a plugin?


So, I have Hudson setup locally, and I am using an open source plugin that lets me create AWS Stacks from CloudFormation using the AWS SDK. However, the plugin fails because I am on a VPN, and I need to go through a proxy server. I have configured Hudson to use my proxy server for downloading (and updating) plugins. My question is - is there any way for my plugin to access Hudson's proxy settings and re-use those so that I don't have to enter the proxy settings in the plugin as well? I checked to see if Hudson happened to be setting the http.proxyHost, etc, System properties, and it doesn't appear that it is.


Solution

  • After downloading the Hudson code and looking at how it uses the proxy settings, I was able to utilize those in my plugin with the following lines:

        Hudson hudson = Hudson.getInstance(); 
        ProxyConfiguration proxyConfig = hudson != null ? hudson.proxy : null;
    

    From there, I can call proxyConfig.name, proxyConfig.port, proxyConfig.getUserName(), and proxyConfig.getPassword() to get the settings that I needed.