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

<p>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.</p>

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

CC BY-SA 4.0
2019-02-27T19:45:58.463Z
@DanCornilescu: I would again just like to state this is not the default action that happens, most VPN clients these days default to split tunneling. Consumer VPNs that are intended to circumnavigate a network won't, but that's not what we are talking about here.
ZaxLofful
CC BY-SA 4.0
2023-04-11T18:05:20.630Z
@ZaxLofful is correct, unless "route all traffic" is explicitly set (either pushed from the server side, or in the client configuration), VPNs do not "effectively disconnect" from the local network. My router has my work VPN open on it 24/7, and I can still access the rest of the internet, and any traffic not specific to my work network is not routed through my work network.
Doktor J
CC BY-SA 3.0
2017-08-25T14:11:15.693Z
what a bummer, but that makes perfect sense. Thanks!
Alex
CC BY-SA 4.0
2018-09-13T23:18:10.690Z
this is not accurate at the time of me writing this comment, nor do I think it ever was....just saying
ZaxLofful
CC BY-SA 4.0
2018-09-14T01:43:40.327Z
@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
CC BY-SA 3.0
2017-08-22T18:12:32.873Z
2017-08-22T18:12:32.873Z
Dan Cornilescu
<p>If you want to VPN for a jenkins task you would want to use the OpenConnect plugin as you mentioned.</p>

<p>Here are the steps to do that:</p>

<p>On linux (debian based)</p>

<pre><code>sudo apt-get install openconnect
</code></pre>

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

<pre><code>jenkins ALL=NOPASSWD:/usr/sbin/openconnect*
jenkins ALL=NOPASSWD:/bin/kill*
</code></pre>

<p>The you will get an option in the Jenkins run task called:</p>

<pre><code>Connect to Cisco AnyConnect VPN
</code></pre>

<p>Can also be found here:
<a href="https://stackoverflow.com/questions/35151072/deploy-with-jenkins-to-vpn/43357784#43357784">https://stackoverflow.com/questions/35151072/deploy-with-jenkins-to-vpn/43357784#43357784</a></p>

CC BY-SA 4.0
2018-09-13T23:17:28.057Z
2018-09-13T23:17:28.057Z
ZaxLofful
<p>Is there a way to connect to a VPN for the duration of a Jenkins job? (freestyle or pipeline, I can work with either). </p>

<p>I scoured the plugin list figuring someone might have developed something, but the only page found was this <a href="https://wiki.jenkins.io/display/JENKINS/OpenConnect+Plugin" rel="noreferrer">OpenConnect</a> page with no actual code developed, so that seems to be out. </p>

<p>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.</p>

CC BY-SA 4.0
2019-04-04T05:35:13.770Z
I would just like to reiterate (for the OP and others who might find this) that you can in fact do this if you are still looking, please take a look at my answer.
ZaxLofful
<jenkins><vpn>
Jenkins job using VPN?
Alex
# Jenkins job using VPN?

(Asked by: username_0 on 2017-08-22)

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](https://wiki.jenkins.io/display/JENKINS/OpenConnect+Plugin) 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.

**Tags:** jenkins, vpn

> **Comments:**
> **username_1**: I would just like to reiterate (for the OP and others who might find this) that you can in fact do this if you are still looking, please take a look at my answer.  

---

## 2 answers

### Answer by username_2 on 2017-08-22. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: what a bummer, but that makes perfect sense. Thanks!  
> **username_1**: this is not accurate at the time of me writing this comment, nor do I think it ever was....just saying  
> **username_2**: @username_1 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.  
> **username_1**: @DanCornilescu: I would again just like to state this is not the default action that happens, most VPN clients these days default to split tunneling. Consumer VPNs that are intended to circumnavigate a network won't, but that's not what we are talking about here.  
> **username_3**: @username_1 is correct, unless "route all traffic" is explicitly set (either pushed from the server side, or in the client configuration), VPNs do not "effectively disconnect" from the local network. My router has my work VPN open on it 24/7, and I can still access the rest of the internet, and any traffic not specific to my work network is not routed through my work network.  

---

### Answer by username_1 on 2018-09-13. Score: 3

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


---

