0

I'm new to PowerShell I want to send 3 different responses to 3 different user prompts that I get when running a PowerShell script using another PowerShell script in Jenkins

I tried

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
[System.Windows.Forms.SendKeys]::SendWait("y")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("y")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("dummytext")
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}") 
$command =  "D:\testing\source\sample.ps1"  + " -param1 'dummyParam'"
Invoke-Expression $command

but I keep getting this error

Exception calling "SendWait" with "1" argument(s): "Access is denied"
At D:\testing\powershell\testing.ps1:6 char:1
+ [System.Windows.Forms.SendKeys]::SendWait("y")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : Win32Exception
 
Build step 'PowerShell' marked build as failure
Finished: FAILURE

Does anyone how to fix this issue

  • Jenkins processes are non-interactive, so `SendKeys` is not allowed. The answer here has a great explanation about why, and what your other options are: https://stackoverflow.com/a/14896936/7411885 – Cpt.Whale Mar 29 '22 at 19:40
  • Does this answer your question? [Can Jenkins handle an gui/non-gui interactive python or java program?](https://stackoverflow.com/questions/14885079/can-jenkins-handle-an-gui-non-gui-interactive-python-or-java-program) – Cpt.Whale Mar 29 '22 at 19:43

0 Answers0