Remotely Start Full Screen RDP Session from Server1 to Server2 - amazon-ec2

We are trying to integrate MicroFocus UFT testing into an Azure DevOps CI\CD pipeline using a self-hosted EC2 build agent (let's call the build agent UftServer). UftServer has MicroFocus UFT One installed and the pipeline uses the MicroFocus Azure DevOps extension see here to start the test.
Everything works as expected when a full screen RDP session is open to UftServer. When the pipeline runs, we can watch UFT One open our application and run the specified test. Results post back to Azure DevOps with pass\fail and life is good.
However, when the RDP session is closed, the UFT pipeline step fails to execute the test. It mentions a credentials error, but the problem clearly seems to be the closed RDP session.
From the test results we assume that a full screen RDP session needs to be active for UFT One to execute the tests properly (it detects the screen resolution so that it knows where certain menus are in our application).
So, rather than open the RDP session to UftServer from my local system (which won't necessarily be open when the pipeline runs), we created a second build agent RDPLauncher in the pipeline (also self hosted EC2), and execute the following script on it before launching the UFT test on UftServer:
$RemoteUftServer = "UftServerIp"
$RemoteUftUser = "Administrator"
$RemotePwSecretId = "uft"
$RemoteUftPw = ((Get-SECSecretValue -SecretId $RemotePwSecretId).SecretString | ConvertFrom-Json).password
reg add "HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client" /v "AuthenticationLevelOverride" /t "REG_DWORD" /d 0 /f #to disable cert check
cmdkey /generic:"$RemoteUftServer" /user:"$RemoteUftUser" /pass:"$RemoteUftPw" #to set RDP creds
mstsc /v:"UftServerIp" /admin /f
Write-Host "mstsc command ran successfully, qwinsta results:"
qwinsta
When we run this script manually RDPed into RDPLauncher, the full screen RDP session to the UftServer opens as expected and runs the test.
Further, we can disconnect from RDPLauncher and the RDP session from RDPLauncher to UftServer remains open and the pipeline still runs successfully.
It is great to not have the RDP session open from my local system, but the pipeline still lacks a critical automation piece.
When the pipeline runs the above script on RDPLauncher (rather than me running it manually RDPed into RDPLauncher), it succeeds, but then the UFT test fails as if the session isn't open.
So, from the pipeline, how do we remotely open the full screen RDP session from RDPLauncher to UftServer?
The script above works when I run it from RDPLauncher, but doesn't seem to have the same effect when the Azure DevOps Agent service runs it from the pipeline.
Both build agents are running Windows 10.
Any help is appreciated :)

I suggest you to first configure everything before the pipeline run.
1, Remember the credential.
2, After the above steps, click remember your password after you input the password.
And then, in your pipeline, only need a pipeline definition like the below will be able to connected to the remote server with rdp file(no need other interactive steps.):
trigger:
- none
pool: VMAS #This is a self hosted agent pool, the pipeline is runnning based on a server in this agent pool, and the rdp file is also in this server.
steps:
- script: |
# echo %username%
# mkdir "C:/xxxyyyzzz"
C:\Users\Administrator\Desktop\VM.rdp # Here is the path of the rdp file on my side.
displayName: 'Run a one-line script'

Related

stop and start IIS server for TFS build Access denied

I need to stop and start IIS server for TFS build. When do this using .bat file iisreset /stop, similarly for start.
When I do this I get
Access denied, you must be an administrator of the remote computer to use this command. Either have your account added to the administrator local group of the remote computer or to the domain administrator global group.
Please note: This is Windows server 2019
I am already admin of this machine.
I have given read/write access to everyone in this folder.
I have unset EnableLUA to '0' in the registry as told in link for site
Above all these, I restarted machine.
I still get error in TFS build.
When you start a build in TFS the execution of that build is effectively done by a build agent. A build agent is just a service running on any particular machine. So, your batch file that shall start/stop the IIS service will be executed by whatever build agent is running your particular build.
This in terms means that your batch file is executed by the user that is used to run the build service. If that user does not have the necessary admin rights you face this particular error message.
What you need to do is make sure that all accounts that you use to run your build agents have administrative permissions on whatever machine you want to start/stop IIS.
You are trying to do IISRESET in your batch script. You need to be an Administrator as basic right to execute IISRESET command. So the account which the build is running needs to be part of the Admin group on the box.
Other approach is to stop and start w3svc using sc config commands or NET STOP WAS /Y and NET START W3SVC
Both of your answers are correct, I added the 'Network Service' of TFS to admin group of machine. Then build was success. Administrative tools>Computer Management> Local Users and Groups>Groups>
Inside Administrators and Users add 'Network Services'. If you don't find 'Network Service' then change location to your computer node and add them.

Unable to execute the windows bash script on Jenkins slave

As a part of regression testing need to run the bash script on windows machine which actually open the chrome browser and traverse the website and generate the test report.
when i try to execute it through jenkins all the test cases are getting failed as its unable to open the browser, the same is getting passed when we logon to the remote windows server and execute the script manually.
NOTE: Have provided the same credentials on jenkins slave windows service
found below log on event manager
Activation of app Microsoft.Windows.Cortana_cw5n1h2txyewy!CortanaUI failed with error: This app can't be activated by the Built-in Administrator. See the Microsoft-Windows-TWinUI/Operational log for additional information.
Could you please help me here..
Hi can you enable the option Allow service to interact with desktop for the jenkins slave service on your windows slave machine.
You can enable it by going In services.msc > right click on service name > Properties > Log On > Allow service to interact with desktop

Is there any way to open the CMD through teamcity so it will open and displayed on the desktop?

I have a batch job that i want to deploy from Teamcity to several servers,
to access several servers i use Winexe tool.
the batch is running but i can't see the session because it's started from teamcity,
but i can see that its running when looking at the process list.
My issue is that sometimes this job is having some errors,
which are being displayed on the cmd window when i run it manualy
but since i'm running it through TeamCity i can't see the CMD window so i can't see the error.
My question is:
Is there any way to open the CMD through teamcity so it will open and displayed on the desktop when i access the server as the same user?
note: bare in mind that i need to deploy it to several servers so i can't install several
agents via ZIP File.
So I found kind of a work-around to solve this problem,
I created a schedule task in windows that will run my batch.
when creating this task you need to set those settings:
1.) Run as: the user name that TeamCity is logging in.
2.) check the Run only if logged on check box.
3.) in the security tab give the user you use full permitions.
In order to run the schedule task you need to run this batch script:
Schtasks.exe /Run /TN name_of_schedule_task

Remotely running "vmrun command" on server machine from jenkins

I have windows 7_x64 Virtual Machine on Server machine running on Windows Server 2008 R2. I want to run this VM from jenkins (CI tool which executes batch file, running on same server).
I am using vmrun utility to do so.
When i run
vmrun -T ws -gu *** -gp *** start "vmx file path.vmx"
this executes fine on server command prompt (locally). but when i try to exceute the same from any of the client machine (by visiting jenkins site) I get
Error: There was an error in communication
After some troubleshooting, I can say vmrun command is not responding whenever it is evoked remotely. but it is confusing me, because I have jenkins which is running those commands is installed on same server. i am just running job from thin client. how does that make any difference?
Could anyone help me troubleshooting this issue?
Thanks!
For reference:
*Server machine(host): Windows Server 2008 R2
*Virtual machine(guest): Windows 7 x64
*Jenkins : Installed on same server (host)
*client : remote windows machine, accesses the jenkins instance from browser and triggers the job
*problem/error : vmrun commands dont execute.
Jenkins does not execute anything on "client" (i.e. the machine with the browser from which you accessed Jenkins instance). Jenkins will only execute anything on Master (what you called "server machine") or Slave nodes.
Now, there can be several differences between running the command from your local command prompt (on server) and through Jenkins. The primary difference is that Jenkins runs under a separate session, usually under a separate user, which may have different permissions, however that depends on how you have installed and configured the Jenkins session.
To identify if there are any Environment variable differences, type set on your local command prompt, and then execute Jenkins with just set in the build step. Compare the two. Other than Jenkins specific variables, everything else should be same.
Also, verify that your Jenkins user (the one running the service) has permissions to do whatever your are doing.

How to force Jenkins to launch webpage/ cmd prompt in client (user's) machine?

The job that I was trying to create in Jenkins would require launching a webpage on the user’s browser once the build is successful (Jenkins is installed on a remote server). For doing this I put the following line in the " Build - Execute Windows batch command" section of the job’s Configure page:
START http://google.com
While the build was successful, it did not launch the page. I have a hunch, this line will try to launch the webpage in the remote Jenkins server (it did not launch anything in the slave node though). My question is, how do I force the Jenkins job to launch the webpage in the user’s default browser?
I tried launching client's cmd.exe - this did not work either.
Jenkins master, slave, user's client - everything is on Windows. Jenkins version 1.46.
Thanks!
By "launch in client's machine" you mean the user that is accessing the web interface of Jenkins? No, this won't happen. It can be quite a security risk too.
You can do what you are asking either on the master or the slave. Jenkins does not directly execute anything that is not on master/slave. It is possible to spawn a slave on user's machine, and when the job is run, it will execute the command on the slave.
Or if the user provides his/her computer IP address as a parameter to the job, you could use PsExec to connect to user's computer to execute a command.

Resources