Connect to VPN connection before GIT pull
Asked Answered
B

2

6

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.

Bingle answered 12/6, 2017 at 4:43 Comment(4)
why wouldn't you establish it once and forever? Using the OS tools instead.Cita
@Cita Due to the security and resource concerns as a practice we don't keep the VPN connection up forever. Before GIT pull we start VPN and after GIT pull we stop the connection. That's a requirement.Bingle
You need reassess your security policies, since the solution you have or are going to implement is not more, but less secure.Cita
@Cita Actually here the security perspective is affecting the test environment to the live environments. However changing the security policies may get a long time. Any help is appreciated.Bingle
I
0

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.

Innes answered 12/6, 2017 at 6:4 Comment(0)
S
0

you can try:
step 1: in jenkins:
1.1 create New Item>Freestyle project
1.2 in Build> Add build step> Execute shell> add cmd:

nmcli con up id NAME


show your connection NAME:

nmcli con


note: if you use CI-CD, you can hook in here!
step 2: open your Item in jenkins:
in tab Build Triggers > select Build after other projects are built> Project to watch
config name item you create in step 1
step 3: create new Item in jenkins(down your connect)
3.1 in tab Build Triggers > select Build after other projects are built> Project to watch
config name your item
3.2 in tab Build > add Execute shell> add cmd

nmcli con down id ConnectionName


Good luck! =)))

Spate answered 1/8, 2022 at 4:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.