Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-7830

using environment variable for local port of ssh tunnel

      I use an environment variable to set the port used by the local server that I want to test. I do this because we want to be able to build/test the hudson job on multiple slave nodes at the same time. We currently have those slave nodes running on the same machine. If the port is hard coded then I can't startup multiple local servers at the same time because the port will be the same for each and will conflict.

      So it would be helpful if the sauce-ondemand plugin would allow using environment variables for the "Local Port" setting.

          [JENKINS-7830] using environment variable for local port of ssh tunnel

          Lorrin Nelson added a comment -

          I would appreciate this too. I would like to use the Sauce OnDemand plug-in with the Port Allocator plug-in.

          Lorrin Nelson added a comment - I would appreciate this too. I would like to use the Sauce OnDemand plug-in with the Port Allocator plug-in.

          Ross Rowe added a comment -

          Hi, the latest version of the plugin (v1.11) should support this. The host name and port will be stored in the SELENIUM_HOST and SELENIUM_PORT environment variables. They default to 'localhost' and '4444' respectively - the port will default to 4445 if Sauce Connect is enabled. These values can be overriden via the 'Advanced' options on the Sauce OnDemand configuration settings for a Job.

          Let me know if you have any problems, or if you need any further information.

          Cheers,

          Ross

          Ross Rowe added a comment - Hi, the latest version of the plugin (v1.11) should support this. The host name and port will be stored in the SELENIUM_HOST and SELENIUM_PORT environment variables. They default to 'localhost' and '4444' respectively - the port will default to 4445 if Sauce Connect is enabled. These values can be overriden via the 'Advanced' options on the Sauce OnDemand configuration settings for a Job. Let me know if you have any problems, or if you need any further information. Cheers, Ross

          Lorrin Nelson added a comment -

          Hey Ross, thanks for the quick turn-around! I'm a little confused by your response though. My (and I think the original poster's) intent was to be able to use environment variables in the existing Jenkins Tunnel Configuration fields. E.g. instead of entering a specific number, I want to put $MY_VARIABLE as the Local Port. $MY_VARIABLE will be set by some other process or plug-in and Sauce OnDemand will consume it at runtime.

          If I'm following you right, your change was to publish the values (which still must be directly specified or defaulted) into new variables?

          Cheers!
          -Lorrin

          Lorrin Nelson added a comment - Hey Ross, thanks for the quick turn-around! I'm a little confused by your response though. My (and I think the original poster's) intent was to be able to use environment variables in the existing Jenkins Tunnel Configuration fields. E.g. instead of entering a specific number, I want to put $MY_VARIABLE as the Local Port. $MY_VARIABLE will be set by some other process or plug-in and Sauce OnDemand will consume it at runtime. If I'm following you right, your change was to publish the values (which still must be directly specified or defaulted) into new variables? Cheers! -Lorrin

          Ross Rowe added a comment -

          Okay, the resolving of the environment variables in the configuration fields sounds reasonable, and it shouldn't be too difficult. And yes, my recent change was to store the actual values into updated variable names.

          I'll let you know when I've got an updated version of the plugin that includes the change.

          Cheers,

          Ross

          Ross Rowe added a comment - Okay, the resolving of the environment variables in the configuration fields sounds reasonable, and it shouldn't be too difficult. And yes, my recent change was to store the actual values into updated variable names. I'll let you know when I've got an updated version of the plugin that includes the change. Cheers, Ross

          Ross Rowe added a comment -

          Hi Lorrin, version 1.12 of the plugin now supports the resolving of environment variables when included on the Host/Port fields. Let me know if you have any problems with it.

          Cheers,

          Ross

          Ross Rowe added a comment - Hi Lorrin, version 1.12 of the plugin now supports the resolving of environment variables when included on the Host/Port fields. Let me know if you have any problems with it. Cheers, Ross

          Lorrin Nelson added a comment -

          Hi Ross, thanks again.

          Based on GitHub history, looks like the change went into 1.13 so went with that.

          In src/main/java/hudson/plugins/sauce_ondemand/SauceOnDemandBuildWrapper.java I think the regex is too restrictive:

          Pattern ENVIRONMENT_VARIABLE_PATTERN = Pattern.compile("[$|%]([A-Z]+)");

          (I tend to have underscores in my environment variables.) This StackOverflow discussion suggests

          [a-zA-Z_][a-zA-Z0-9_]*

          might be a good regex.

          Also the help text for the port should say port/_PORT instead of host/_HOST in this line: "The value of the host will be stored in the SAUCE_ONDEMAND_HOST environment variable."

          Not working for me yet, but possibly config error on my end to iron out.

          Lorrin Nelson added a comment - Hi Ross, thanks again. Based on GitHub history, looks like the change went into 1.13 so went with that. In src/main/java/hudson/plugins/sauce_ondemand/SauceOnDemandBuildWrapper.java I think the regex is too restrictive: Pattern ENVIRONMENT_VARIABLE_PATTERN = Pattern.compile( "[$|%]([A-Z]+)" ); (I tend to have underscores in my environment variables.) This StackOverflow discussion suggests [a-zA-Z_][a-zA-Z0-9_]* might be a good regex. Also the help text for the port should say port/_PORT instead of host/_HOST in this line: "The value of the host will be stored in the SAUCE_ONDEMAND_HOST environment variable." Not working for me yet, but possibly config error on my end to iron out.

          Lorrin Nelson added a comment -

          BTW, what's got me confused is that I'm upgrading from an old version of the plug-in in which you configured both ends of the SSH tunnel (like this http://wiki.hudson-ci.org/display/HUDSON/Sauce+OnDemand+Plugin). With the current UI, you only input a "Sauce OnDemand Host" and "Sauce OnDemand Port". What does that mean? Don't I need a host and port to point the browser at (formerly "domain" and "remote port") and then a host and port that traffic should go to on my local network (formerly "local host" and "local port"). In the current UI, I don't get whether I'm configuring the port the browser should hit to go into the tunnel or the port my app is listening on when the traffic comes out.

          Lorrin Nelson added a comment - BTW, what's got me confused is that I'm upgrading from an old version of the plug-in in which you configured both ends of the SSH tunnel (like this http://wiki.hudson-ci.org/display/HUDSON/Sauce+OnDemand+Plugin ). With the current UI, you only input a "Sauce OnDemand Host" and "Sauce OnDemand Port". What does that mean? Don't I need a host and port to point the browser at (formerly "domain" and "remote port") and then a host and port that traffic should go to on my local network (formerly "local host" and "local port"). In the current UI, I don't get whether I'm configuring the port the browser should hit to go into the tunnel or the port my app is listening on when the traffic comes out.

          Ross Rowe added a comment -

          Hi Lorrin,

          Thanks for pointing out the deficiency in the environment variable regex, I'll incorporate your suggestion into the next version (and update the help text).

          With regards to the host/port changes, we removed the domain/remote port fields as they were used by an older version of Sauce Connect, and weren't required by the latest version of Sauce Connect.

          The Host/Port fields are used to populate the environment variables that can be referenced by your Selenium tests to configure the RemoteWebDriver/DefaultSelenium instance.

          If you need to specify a URL for the Selenium tests to run against, you can select 'Selenium 1' from the Selenium Version field, and populate the 'Starting URL' field. This will populate a SELENIUM_STARTING_URL environment variable, which you can reference from your tests. The

          By default, Sauce Connect will be running on port 4445, but this port can be changed by specifying a value in the 'Sauce OnDemand Port' field.

          Hope this helps, let me know if things are still unclear.

          Cheers,

          Ross

          Ross Rowe added a comment - Hi Lorrin, Thanks for pointing out the deficiency in the environment variable regex, I'll incorporate your suggestion into the next version (and update the help text). With regards to the host/port changes, we removed the domain/remote port fields as they were used by an older version of Sauce Connect, and weren't required by the latest version of Sauce Connect. The Host/Port fields are used to populate the environment variables that can be referenced by your Selenium tests to configure the RemoteWebDriver/DefaultSelenium instance. If you need to specify a URL for the Selenium tests to run against, you can select 'Selenium 1' from the Selenium Version field, and populate the 'Starting URL' field. This will populate a SELENIUM_STARTING_URL environment variable, which you can reference from your tests. The By default, Sauce Connect will be running on port 4445, but this port can be changed by specifying a value in the 'Sauce OnDemand Port' field. Hope this helps, let me know if things are still unclear. Cheers, Ross

          Ross Rowe added a comment -

          Apologies for the delay in replying to this issue. The change to the regex for environment variables was released in version 1.14 (version 1.20 is the latest version)

          Ross Rowe added a comment - Apologies for the delay in replying to this issue. The change to the regex for environment variables was released in version 1.14 (version 1.20 is the latest version)

            rossrowe Ross Rowe
            scytacki scytacki
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: