Is there a way to connect to a VPN for the duration of a Jenkins job? (freestyle or pipeline, I can work with either).

I scoured the plugin list figuring someone might have developed something, but the only page found was this OpenConnect page with no actual code developed, so that seems to be out.

We're running Jenkins on Ubuntu AWS boxes, if that changes anything. I'd prefer the ability to connect and disconnect in a single job, rather than making everything run on VPN.

up vote 3 down vote accepted

I think that it's very difficult, if not impossible, to achieve something like this.

The reason is that once the machine running Jenkins is connected to the VPN it is also effectively disconnected from the original network it was connected to, which means Jenkins on that machine will loose connection with the rest of your Jenkins setup.

The only way that might work would be if using completely standalone one-machine Jenkins setups.

  • what a bummer, but that makes perfect sense. Thanks! – Alex Aug 25 '17 at 14:11
  • this is not accurate at the time of me writing this comment, nor do I think it ever was....just saying – ZaxLofful Sep 13 at 23:18
  • @ZaxLofful The VPN client at least alters the routing table making the local network unreachable (by usual means, which is what I mean by "effectively disconnected"). So at least you'd need to run some other script to carefully restore connectivity without impairing the VPN traffic. And, if the VPN client isn't smart enough to revert to the original routing table due to this script's intervention you'll also need to intervene after disconnection from VPN as well. Donno if something else besides routing also needs addressing. – Dan Cornilescu Sep 14 at 1:43

If you want to VPN for a jenkins task you would want to use the OpenConnect plugin as you mentioned.

Here are the steps to do that:

On linux (debian based)

sudo apt-get install openconnect

Add the following lines to the bottom of /etc/sudoers (ubuntu configuration)

jenkins ALL=NOPASSWD:/usr/sbin/openconnect*
jenkins ALL=NOPASSWD:/bin/kill*

The you will get an option in the Jenkins run task called:

Connect to Cisco AnyConnect VPN

Can also be found here: https://stackoverflow.com/questions/35151072/deploy-with-jenkins-to-vpn/43357784#43357784

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.