Why does this jenkins job never complete? - batch-file

I have a windows 8 jenkins slave (really more than one) and I want to have a task which clones a mirror of a git repository if it doesn't exist and always fetches latest.
I've got this 'execute windows batch' step:
if not exist "server-reference" (
git clone --mirror git#ssh.com:something/somewhere.git server-reference
)
pushd server-reference
git fetch --all
popd
exit /B %ERRORLEVEL%
The console output for the job gets to this point
c:\jenkins\workspace\thing\server-reference>git fetch --all
Fetching origin
and never finishes
If I switch an exit above the fetch then I get the expected exit.
And if I run the batch file commands as the jenkins user on the windows box everything works as expected. So I (think I) know that the git fetch --all runs on the slave without prompting for input
How do I amend this script so that it completes when Jenkins runs it?

A number of things can cause this problem. Here are things that have worked for me in the past.
I know you stated this above, but just to double-check: Confirm that when you run git fetch --all manually on the slave machine, it doesn't prompt you for a password. If it does, Jenkins would get stuck on that step, so you'll need to set up an SSH keypair.
Make sure that you are calling C:\Program Files (x86)\Git\cmd\git.exe and not C:\Program Files (x86)\Git\bin\git.exe in Jenkins. The second one can cause this problem in certain versions of git.
On the slave machine, set the environment variable HOME to C:\users\[username], filling in your user's username. (For older OS's it was C:\Documents and Settings\[username].) Then recycle the Jenkins service and try again.
Double check that in Administrative Tools > Services, the Jenkins slave service "Log On As" is set to your user and the password is correct. If not, set those values, recycle the Jenkins service and try again.
If none of the above worked, try uninstalling and reinstalling git. And if you aren't using it, try installing the newest version of git.

Related

mongodb server not running as a background process

I recently downloaded mongodb and robo 3T. now im new to using mongodb on my system as i normally only use it online. well ever since i installed mongodb, it is meant to run as a background process forever but it never does. for it to even show on my task manager i have to start the service by myself and whenever i restart my laptop its stopped again. my point is, because of this problem, robo 3T hasnt been able to connect to mongodb even though i start the service by myself. did i do anything wrong when installing mongodb and how do i fix this problem?
I don't like the .msi installer to create the MongoD service. Usually I prefer the manual way of doing it. It gives more control and you know what actually happens.
Install MongoDB with MSI installer, disable option "Install MongoD as a Service"
Create mongod.cfg file according to your preferences.
You may use <Installation Path>\Server\5.0\bin\mongod.cfg as template. Pay attention to Windows Service Options.
Install the service by running mongod.exe --config "<full path of mongod.cfg file>" --install
Note, you need to run mongod.exe --install with Administrator privileges. See https://docs.mongodb.com/manual/reference/program/mongod.exe/
Check your Service Manager services.msc for any already existing Mongo services. You can remove them with mongod.exe --config "<mongod.cfg file>" --remove or sc.exe delete <service name>

SQL Server Agent Job and gsutil

I can successfully run a gsutil command with a windows domain account from the command line in Windows (setting up service account key etc.). When I try to run the same command from a SQL Agent Job using a CmdExec task the job hangs and doesn't complete. I can't see any logging so have no clue what it's waiting for. I've setup the job to run with the same Proxy User that i use to run the gsutil command manually.
Any ideas how I can get this to work or how to see more logging?
Are you using standalone gsutil? Or did you get it as part of installing the Cloud SDK (gcloud)?
If the job hangs for a long time, it could be stuck retrying multiple times. To test if this is the case, you can set the num_retries option to be very small, but above 0 (e.g. 1) either in your .boto file or the the command arguments via this option:
gsutil -o 'Boto:num_retries=1' <rest of command here...>
A second thing to note (at least for the version of gsutil that doesn't come with gcloud) is that gsutil looks for your boto config file (which specifies the credentials it should use) in your home directory by default. If you're running gsutil as a different user (maybe your SQL Agent Job runs as its own dedicated user?), it will look for a .boto file in that user's home directory. The same should apply for the gcloud version -- gcloud uses credentials based on the user executing it. You can avoid this by copying your .boto file to somewhere that the job has permission to read from, along with setting the BOTO_CONFIG environment variable to that path before running gsutil. From the cmd shell, this would look something like:
set BOTO_CONFIG=C:\some\path\.boto && gsutil <rest of command here...>
Note: If you're not sure which boto config file you're normally using, you can find out by running gsutil version -l and looking at the line that displays your config path(s).

installing windows service from command line "The specified service has been marked for deletion"

I am trying to create a batch file to automate uninstalling, building and reinstalling a windows service.
After uninstalling when I try to reinstall I get the error: The specified service has been marked for deletion.
here is the batch script:
#ECHO off
set filePath=<myfilepath>
set serviceName=<myservicename>
sc query %serviceName% > nul
if %ERRORLEVEL% EQU 0 net stop %serviceName% & sc delete %serviceName%
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe C:\Users\Christopher\Desktop\TFS\MOC\LaneUpdateService\LaneUpdateService.sln /property:Configuration=Debug
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe %filePath%
sc start %serviceName%
I do not have task manager, services or event viewer open, there are no other users logged in. I have tried deleting the reg key for my service, with no luck. If I run my script again after it failing it will install correctly. Is there a way to manually make sure the service is fully deleted?
The problem was that after stopping my service there was still a process running. I altered my onstop method to make sure all processes were stopped correctly. now the batch file works correctly. As #Harry Johnston suggested I will be adding a while loop to the batch file.

TFS Post Build script executing twice

I have a post build batch file being executed after a TFS build. It compiles an Inno Setup script and places the generated exe in a drop folder. It then tries to run that exe and install the application on the server. It runs the exe; however, this hangs the build.
The issue is, it seems to execute it twice. I can see 2 process running for the installer in task manager. If I execute the batch file manually, there are no issues - it's only when TFS executes it, I run into this problem.
Post Build Batch File
cd "C:\Program Files (x86)\Inno Setup 5"
iscc "%scriptDir%\Script.iss"
cd "C:\Deployment"
start Installer.exe /VERYSILENT
Any ideas would be greatly appreciated. Scratching my head with this.
From my findings, the post build script was NOT executing twice.
I believe the issue had something to do with permissions. The build service was being executed via the LocalService account which did not have permission to install the application. I THINK the build service tried to execute the installer but was denied and silently failed (and possibly tried again causing the additional installer process).
Solution: Set the Build Service to run under a different account with the permissions to install applications.

Execute windows batch command from Jenkins fails but runs fine in cmd.exe

I am trying to run this command in jenkins after a MSbuild
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Y: is a mapped network drive. This runs fine in cmd.exe but when trying to run it in Jenkins, I am getting the error Invalid drive specification.
Here is the output from jenkins:
Time Elapsed 00:00:04.03
[trunk] $ cmd /c call C:\Windows\TEMP\hudson3389873107474371072.bat
C:\Program Files (x86)\Jenkins\workspace\trunk>xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Y:\Extraction_Zone\Jenkins\" /E
Invalid drive specification
0 File(s) copied
C:\Program Files (x86)\Jenkins\workspace\trunk>exit 4
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Any help would be appreciated.
I too had a similar issue once. Try granting the Jenkins service "Logon as This account" right under services.msc and make sure the account you type there is the same as the one you use for running cmd.exe.
These commands based on Java JAR files worked for me:
cmd
net use x: \\
xcopy "dist\" x:\ /Y
And that's it! I spent lot of time figure out this issue and nothing worked until I wrote CMD and NET USE!
Neither I didn't need to change permission on jenkins service nor use runas command.
But I must mention that everyone had read and write access to the network drive.
I had the same issue with my Windows Task running a batch file (I know it is not exactly same) where I tried to copy file to network location i.e. shared drive. I used the UNC path and mapped drive as well but the error was same. For me it was error number 4 - MS DOS error code.
The solution was to use net use command! Hope that it helps.
Easy fix for most things.
Make a batch command with what your trying to run, filename.bat with the command prompt text inside.
Make a normal windows shortcut for the batch command, edit the shortcuts advanced properties and check the "Run as admin" (tricky tricky).
Now run the filename.lnk shortcut from jenkins command line call, this will get you around all the jazz.
:)
The solution of adarshr (i.e., modifying the log on credentials of the service) has worked for me for a part of the problem: in my case, this allowed me to successfully check out a mercurial repository (using ssh protocol), which I could not do when using 'Local System account'.
However, I still have different behavior between running a command-line script or running the same script from a jenkins 'execute shell' script in the build section. In my case, I compile a Python extension. In Jenkins, I cannot import the extension (I don't see any error, but the execution simply stops, so I suspect it crashes).
If I uninstall the service and run the slave agent as a Java Web Start, I do get the same behavoir. It is a temporary fix for me, but it means that when I reboot the windows build machine, I have to manually re-start the Java Web Start application.
So -at least in my case- it is clear that this is a credential problem.
Credentials usage documentation: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
I've solved my issue with the CIFS plugin.
Faced similar issue and found two ways to solve.
Type 1:
Tell Jenkins about mapped drive.
1.Goto -> Manage Jenkins -> Script Console (Groovy Script).
2.Run below command
def mapdrive = "net use Y: \\\\copy_nework_address"
mapdrive.execute();
println "net use".execute().getText()
Type:2
1.Goto -> cmd -> run "net use" to know network address
xcopy "C:\Program Files (x86)\Jenkins\workspace\trunk\Projects\results\results\obj\Debug\Package\PackageTmp" "Copy_Network_Address\Extraction_Zone\Jenkins\" /E
Conclusion:- I prefer 2nd types as after every restart i should run Groovy Script.

Resources