0

I have installed an Azure P2S VPN on my Windows computer and I can connect it manually. I also have a PowerShell script to do the job. Here's the script:

rasphone  "Azure-VPN"
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Network Connections')
Sleep 2
$wshell.SendKeys('~')
Sleep 2
$wshell.SendKeys('~')

The $wshell.SendKeys('~') is to replace pressing Enter key when I connect manually.

I can run this script to connect VPN successfully from command line:

> powershell C:\myScript.ps1 True

Now I want to run this script on a Jenkins pipeline. But it seems like this cannot be achieved.

stage('VPN'){       
    bat "powershell C:\\myScript.ps1"
    }

It returns False on the Jenkins console output.

I also tried following the accepted answer here but still no luck (cannot run neither from command line nor on Jenkins)

 > rasdial Azure-VPN /phonebook:%userprofile%\AppData\Roaming\Microsoft\Network\Connections\Cm\<aLongNumber>\<aLongNumber>.pbk

 Remote Access error 623 - The system could not find the phone book entry for this connection.

Is there any workaround for this? My purpose is to use Jenkins pipeline to turn on the VPN, send some files over the network and then turn it off.

Hien Le
  • 301
  • 3
  • 14

1 Answers1

0

You could select to use Jenkin’s Powershell plugin for directly running Powershell scripts on Windows via Jenkins. You could get more references from this blog.

enter image description here

Alternatively, refer to this SO answer, you could invoke a batch file with Jenkins like this for Windows paths:

stage('build') {
  dir("build_folder"){
      bat "run_build_windows.bat"
  }
}

or

stage('build') {
  bat "c://some/folder/run_build_windows.bat"
}
Nancy
  • 26,865
  • 3
  • 18
  • 34