I've just discovered this site and I would like to ask my first question.
I have a pipeline project on Jenkins that basically do this:
- SVN update
- Build
- Deploy
As the deploy target machine is on a different network, I need to start an OpenVPN connection. This works fine using bat 'start openvpn config.ovpn'
.
The problem is that I need to drop the VPN connection once the process has finished and there is no stop command for OpenVPN.
My first approach was to save the process ID that started OpenVPN and kill it later. Something like this:
stage('Connect VPN') {
bat '''wmic process get parentprocessid,name | grep WMIC | tr -d \'WMIC.exe \' > wmic_pid
start openvpn myconfig.ovpn'''
}
stage('Deploy') {
// Deployment process
}
stage('Disconnect VPN') {
env.WMID_PID=readFile('wmic_pid').trim()
bat 'taskkill -pid %WMID_PID% -t'
}
However, for some reason the process ID saved using wmic does not match with the one used by OpenVPN. This procedure works fine when its executed manually on a cmd.
Any ideas?
PS: I'm on a Windows Server 2012.