'Connect to VPN connection before GIT pull

I am trying to setup an application testing environment with Jenkins.

Since the GIT repository is in another separate network, it is required to connect to a VPN connection to establish a connection between Jenkins and GIT.

So, is there any way to establish a VPN connection before the GIT pull step?

I have a CLI command to start/stop a VPN connection. Currently, I use "Post Steps" section's "Execute Shell Script" option to run the command to stop VPN connection.



Solution 1:[1]

You can see if a plugin like OpenConnect could help.
As mentioned in this answer, you would then run a job with a run task called "Connect to Cisco AnyConnect VPN". If that job succeed, then you can run your regular job with a Git url.

For that Git url, you might have to establish an ssh tunnel.

ssh -L3333:git.example.com:22 [email protected]
git clone ssh://git@localhost:3333/example.git

The first command would be part of the first job I mentioned above, the one which starts the VPN.
The second line, the ssh url one, would be the one to use in the Git url field of the second job (the one which should get the sources).
That second job, as a post-build step, can then clone the VPN.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC