Schedule task and .exe - task

I have a scheduled job running an executable file. if I stop the scheduled job then the code of the executable file will continue until the end of the code or it will be terminated abruptly? This job is on windows server 2003.

I created a few month ago a new schedule task. It runs a bat file with this code:
#echo off
pushd
tasklist /nh /fi "imagename eq chrome.exe" | find /i "chrome.exe" > nul ||(start
chrome.exe)
pause
I run chrome via a schedule task witch call the above bat file.
If chrome is running i do not run it again.

Related

Stop Jenkins from running after unstable build

I have a Jenkins job that runs multiple windows batch command.
The current situation is that after the first batch command exits, and is set as unstable, the Jenkins won't stop but it will run the next windows batch command.
E.g.
First windows batch command
Python sys_dir/test1.py
If %ERRORLEVEL% NEQ 0 (
exit 0)
# this job has set if have errorlevel as 2, it will marked as unstable
Second windows batch command
Python sys_dir/test2.py
echo "Should not proceed the second batch if there have failure/unstable during the first windows batch command
See the Execute Windows batch command → ERRORLEVEL to set build unstable's inline help:
[...], the build results will be set to unstable and next steps will be continued.

How to start a console program that does not close after execution by TFS Release Agent

I want to get the TFS Release Agent to run multiple console applications and then keep them running without blocking the release process.
I'm running a Powershell script where the start process function is used to run the .exe files. However, all programs close shortly after opening when this script is called by the Release Agent. When I start the script manually, all windows remain open and it works the way it should.
The Release Agent is in interactive-mode and runs in the foreground at system startup.
I have tried the -Wait argument, it keeps the application open, but does not finish the agent's task and blocks the release.
I also tried the Start-Job command, but it didn't happen at all and I need the processes in the foreground.
Start-Process -FilePath C:\microservices\Hoster\Singlehost.exe -Verb open -PassThru -argument "DataProvider"
The Processes should all be started in foreground, and keep running after the release is finished.
Thanks ;)
The only way I found to solve this was the Windows Task Scheduler.
I schedule a task that only runs once after 60 seconds.
The PowerShell task looks like this:
$startDate=[DateTime]::Now.AddSeconds(60)
schtasks /create /tn "Start Agent" /tr "C:\agent\myagent.exe}/" /sc once /st $startDate.ToString("HH:mm") /sd $startDate.ToString("MM/dd/yyyy") /it /f
You have to run the service with a local or domain account as a service or interactive.
Here is the documentation for the schtaks command.
you can try the START command to run each exe:
START "title" [/D path] [options] "command" [parameters]

Is there any way to start appium server silently?

Use case: I need to start appium server on CI Jenkins and run tests right after that. Tests don't start because appium server starting in debug mode and doesn't switch to another command.
So i have jenkins on Windows machine with the following build steps (as Windows batch command):
start /B node path_to_appium_server\appium.js --address 127.0.0.1 --port 4723
timeout 10
"path_to_tests_runner\vstest.console.exe" "path_to_dll\test.dll"
And in this case, my tests cannot started because jenkins terminate first process (with appium).
Basic issue was with permissions for '*.dll' file which contains tests and which cannot be ran with bat file without 'runas' command (which is waiting for password) from Jenkins.
So my Jenkins job contains 3 Build steps:
execute Windows batch command
start node path_to_appium_server\appium.js --address 127.0.0.1 --port 4723
Run unit tests with VSTest.console (to get this build option you need install VSTest Runner plugin)
specify path to dll and command line parameters
execute Windows batch command
taskkill /F /IM node.exe
Second step resolve permission issue for dll file.
It depends on how are you starting it. In most situations if on Jenkins you have 2 ways:
Start appium and tests in different build "shell execution" steps
If you want to do it in the same build step, just start it in a background with "START /B program".
Requirement
Installed Node.js 0.10 or greater.
At least an appium server instance installed via npm.
using javaclient 3.2.0
AppiumDriverLocalService service =AppiumDriverLocalService.buildDefaultService();
service.start();
service.stop();

Run a background process permanently on a node through a script on Jenkins and let Jenkins build successfully

I am running a background process through a script , this script is invoked when Jenkin starts building. However, the jenkins build gets stuck and on looking at the console it seems it is running the process and waits for it to complete.
This process will never complete, consider this as a server listening to its client.Every build I trigger kills the server process and restarts the process, so I am perfectly handling that scenario.
Is there any way , I can build jenkins successfully?
The exact details depend on your operating system (which you did not tell), but the Jenkins wiki has a page about this: https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build
There is a trick you can do in order you free a Jenkins thread.
What you can do is to execute a bash script through a ssh connection and send it to the background while saving the pid of the process somewhere so you can make checks further.
The format of the command would be:
ssh -n _hostname_ "_commands_ & echo \$! > \"_path_to_pid_file_\"" &
Example with a never-ending program:
ssh -n myhost.domain.com "tail -f /var/log/my.log & echo \$! > \"$WORKSPACE/pid\"" &
This example will spawn the tail process listening forever for new changes in the /var/log/my.log file and store its pid in the $WORKSPACE/pid file.
When executed from a Jenkins job the ssh process will exit immediately while the commands sent to the background will remain in execution in the specified host.
I do this in order to maintain always one of the services I run in my build farm in-sync with the latest code modification of it in the repository.
Just have a job that ssh' into the target machine and then kill the process, update the service and re-launches it.
This could be a bit cumbersome but it works great!

How to wait for job to finish when using jenkins-cli.jar to run a slave job?

I have a Jenkins slave ( at localhost:8000 ) and I am executing it ( link ) from a Jenkins Master ( at localhost:8080 ). The basic idea here is to run the remote job and wait until the job is finished.
java -jar jenkins-cli.jar -s http://localhost:8000 build "Test Suite"
Right now, this doesn't wait. I starts the job on the slave and the Jenkins Master says the task is immediately finished although the slave runs for another 30 minutes.
Does anyone know how I can block or check for a signal on the slave to verify it is finished and get the exit status code of the job?
NOTE: My slave test MUST run on the slave because it won't run from Jenkins master, which runs as a service and doesn't allow permissions to start a webbrowser from the test. So, I run the slave in a visible console.
java -jar jenkins-cli.jar -s http://localhost:8000 build "Test Suite" -s
Adding the parameter -s to the build command should trigger the job and return after job is completed
Each windows application returns an exit code to it's parent. Examine the exit code using a windows batch file. Example:
java -jar jenkins-cli.jar -s http://127.0.0.1:9090 build "Test Suite" -s
echo The exit code is %errorlevel%
On successfull job completion you will get:
Completed "Test Suite" #72 : SUCCESS
The exit code is 0
Examine some error scenarios (wrong job name, job creates FAILED and so on)
Note: Running master jenkins not as windows service may be more easy.

Resources