Home > Enterprise >  Jenkins Running power-shell RDP on Windows Agent
Jenkins Running power-shell RDP on Windows Agent

Time:12-23

Im trying to open an RDP file on a Windows agent.. just to get session opened nothing else.

also tried different variation.. p.s the RDP.PS1 creating the RDP file and if i double click it its openning the connection

option 1 :

node('JenkinsWindows') {
 writeFile file: "session.txt", text: "${env.FILE}"
 powershell(". '.\\RDP.ps1'")
 powershell(returnStdout: true, script: """
   Start-Job -ScriptBlock '{cmd /c "mstsc.exe rdp.rdp"}' 
  """)
 sleep 5

option 2: powershell script on the agent .

p.s the rdp.ps1 creating the rdp.rdp file and its works manually

CodePudding user response:

Script blocks { } shouldn't be in quotes, and there's no real reason to launch cmd from powershell. Try something like this:

powershell(returnStdout: true, script: "Start-Job -ScriptBlock {start rdp.rdp}")

You probably don't need to run it as a job either, an even simpler version is:

powershell(returnStdout: true, script: "Start-Process rdp.rdp")

Note: You didn't show how you're creating the RDP file in your question, but be aware that untrusted/unsigned RDP connections may prompt the user before connecting. This prompt may not show up (but could stop your connection), depending on how Jenkins is running:

screenshot

CodePudding user response:

Thank you for the quick replay :) i used it like this (after ALOT of tries)i dont understand why but it didn't work.... also no errors.. what makes it hard.

i've installed a session recorder and this is working somehow ..

                        writeFile file: "session.txt", text: "${env.FILE}"
                        powershell(". '.\\RDP.ps1'")
                        bat("start mstsc rdp.rdp")
  • Related