GitLab Runner not starting process - windows

I have configured a GitLab Runner to run on one of my computers (the computer is Windows and uses Powershell to run yml script commands).
For my repo I have configured the yml file to copy the contents of the build into another directory, then have the runner run: Start-Process -FilePath "$PROJECTNAME.exe" -ArgumentList "$PROG_ARG_1" after changing into that directory.
However, the pipeline succeeds but the process that has been started (using "Start-Process" above) cannot be found on the computer anywhere (has not actually been started).
Am I doing something wrong?
EDIT: it is running just as a "Background Process" (needed to open control panel to verify it)

Related

Docker hangs during build when I try to start a tomcat server

I'm using Windows containers and the microsoft/nanoserver as my base. I'm trying to start up a Tomcat server during the build, but when I do so the build hangs and all I can is cancel it. Unfortunately I have to start the server so it will deploy a war file so that I can then stop the server and alter its configuration. I know I can just run the image, make my changes, and then commit but this seems like cheating. The only thing I can think of is that the startup / catalina script is writing to stdout, but I've tried redirecting to null and it still hangs. Any ideas out there for me to try?
Dockerfile excerpt:
RUN powershell start-process -FilePath .\startup.bat -ArgumentList "/c" -NoNewWindow -RedirectStandardOutput Out-Null
It looks like you can't have a java process running on the image during the build; I was able to fix this by using Start-Sleep to wait for about a minute and then kill any java process running on the machine. The build proceeded after that.

How to Run a Jenkins Job(Powershell command) under context of the logged in Active Directory User

Context:
Created a Domain Controller with Active Directory Setup.
Created another Server with Jenkins-2 installed.(DNS Points correctly to the Domain Controllers)
Installed the Active Directory Plugin
Installed the Powershell Plugin
Created a Powershell Job, with command
Copy-Item -Path \\SFTPServer\Docs\file.txt $Home
Steps:
List item Logged in to Jenkins Server Machine with credentials of globomantics.local\administrator
List item Started Jenkins to be available on localhost:8080
List item Logged in into Jenkins using credentials of globomantics.local\someunderprivilegeduser
List item Run the above created Powershell Job
What happens:
Powershell window appears and runs the command .. in the context of AD User globomantics.local\administrator
What is required:
Powershell command runs in the context of globomantics.local\someunderprivilegeduser
I understand that when we logged into jenkins using globomantics.local\someunderprivilegeduser, a kerberos ticket is generated on this machine. How can i use that ticket to run this powershell command? OR if my approach is completely wrong, what else to do?
Note: let's say globomantics.local\someunderprivilegeduser is NOT allowed to read \\SFTPServer\Docs\file.txt, In this case the Powershell Job should fail. BUT, since the job runs in the context of globomantics.local\administrator, the Job runs successfully.

Bamboo remote build agent cannot find powershell.exe after installing nodejs

I just installed nodejs on one of my build servers (Win Server 2008 R2) which hosts a Bamboo remote agent. After completing the installation and doing a reboot I got stuck in the following situation:
The remote Bamboo build agent is running as a windows service with user MyDomain\MyUser. When a build with an inline powershell task is executing it fails with the error (from the build agent log):
com.atlassian.utils.process.ProcessNotStartedException: powershell could not be started
...
java.io.IOException: Cannot run program "powershell"
...
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
Loggin on to the server as MyDomain\MyUser, I have checked that powershell is in the path:
where powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
I have tried to restart the service and reboot the machine multiple times. No luck. The only thing that works is if I execute my scripts as a bat file with an absolute path to powershell - but I do not want that.
I have searched for solutions on this, but even though this one seems related: Hudson cannot find powershell after update to powershell 3 - the proposed solutions do not work.
What am I missing here?
If you do a default installation of nodejs you will see that it adds nodejs and npm to the path. Sometimes I have seen that the installer adds a user variable named PATH - it might be that the Bamboo agent decides to read the user path without "merging" it with the system path. I think it would be worth a try to give that a look.
As per Atlassian support page, this is related to a bug in Java Service Wrapper. I tried Workaround-2 since there was no user PATH variable in my system. I had to uninstall bamboo agent service and Java 64 versions from the agent machine to apply the workaround-2.

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

Run batch scripts on a remote server (windows) from jenkins

I've got a continuous integration server (Jenkins ) which builds my code (checks for compilation errors) and runs tests and then deploys the files to a remote server (not a war file, but the actual file structure) I do this with a Jenkins plugin which allows me to transfer files via samba, it does this nightly.
Now, what I need to do is run an ant command on the remote server. And after that I need to start the application server on the remote server, the application server is started by running a .bat file from the command line.
I'm pretty clueless how to accomplish this, I know Jenkins is capable of running batch commands, but how do I make them run in the context of the server and not the context of the build server?
If Jenkins on Windows, remote on *nix, use plink.exe (which is essentially command line PuTTy)
If Jenkins on Windows, remote on Window, use psexec.exe
If Jenkins on *nix, remote on *nix, use ssh
If Jenkins on *nix, remote on Windows, (update 2015-01) Ansible http://docs.ansible.com/intro_windows.html has support for calling Windows commands, eg powershell, from a unix/linux machine, https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml
Tell me what OSes are involved (both on Jenkins and remote), and I will flash this out further.
Edit:
The download page for psexec.exe lists all command line options. You will want something along the lines of:
psexec \\remotecomputername -u remoteusername -p remotepassword cmd /c <your commands here>
Replace <your commands here> with actual commands as you would execute them from command prompt.
Note that psexec first needs to install a service, and required elevated command prompt/admin remote credentials to do so.
Also, you need to run psexec -accepteula once to accept the EULA prompt.
Following Slav's answer above, here is a simpler solution for Jenkins (*nix) to remote (windows):
Install an SSH server on your remote windows (MobaSSH home edition worked well for me)
Make sure your Jenkins user, on your Jenkins machine, has the required certification to open an SSH connection with your remote (you can simply open a terminal and ssh to your remote once, then accept the certification. Make sure it is saved for the Jenkins user).
You can now add an execute shell build phase in your Jenkins job which can SSH to your remote windows machine.
Notes :
The established connection might require some additional work - you might have to set windows environment variables or map network drivers in order for your executed commands or batch files to work properly on your windows machines.
If you wish to run GUI related operations this solution might not be relevant (Following my work on running automation tests which require GUI manipulation).
Using Jenkins SSH plugin is an issue, as seen here.
1、i install (MobaSSH home ) on my remote windows server .
2、and install jenkins ssh plugin
3、edit shell eg: go build project
4、it seems something wrong ,
" go: creating work dir: CreateFile C:\WINDOWS\system32\bsh\tmp: The system cannot find the path specified."
I ended up going with a different approach after trying out psexec.exe for a while.
Psexec.exe and copying files over the network was a bit slow and unstable, especially since the domain I work on has a policy of changing password every months (which broke the build).
In the end I went with the master/slave approach, which is faster and more stable. Since I don't have to use psexec.exe and don't have to copy files over the network.

Resources