Is there any way to start appium server silently? - jenkins

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();

Related

Error "$ cmd /c call C:\Windows\TEMP\jenkins6446000872510816227.bat The syntax of the command is incorrect."

Error "$ cmd /c call C:\Windows\TEMP\jenkins6446000872510816227.bat The syntax of the command is incorrect." while executing job for running JMeter test in Jenkins
Going to TEMP folder there was no jenkins6446000872510816227.bat file error aswell. What could be teh issue and what is the solution for this?
Expecting my job build be SUCESS but it is a failure due to this error
Your question doesn't have sufficient amount of details so we cannot troubleshoot your issue.
It's possible to run JMeter script in command-line non-GUI mode like:
c:\apps\jmeter\bin\jmeter.bat -n -t test.jmx -l result.jtl
It's possible to run Windows batch scripts in Jenkins
If it doesn't work for you first check that you can run JMeter test without issues in command-line non-GUI mode on the Jenkins build agent and then double check the syntax of your "Execute Windows batch command" section of the job.
More information: The Complete Guide to Continuous Integration With Jenkins

How to restart Jenkins in Windows

Not able to restart Jenkins manually. Already tried all below ways:
http://localhost:8080/safeRestart
Error message: Jenkins cannot restart itself as currently configured.
Manage Jenkins → Restart Safely Plugin.
Error message: Jenkins cannot restart itself as currently configured.
Not able to find any Jenkins Service in services.msc.
Navigate to jenkins-cli directory in CMD mode
java -jar jenkins-cli.jar -s http://[jenkins-server]/ restart
See below screenshot for error message:
Use command line to stop and start
net stop jenkins
net start jenkins
Simply just do one thing.To restart Jenkins manually, you can use either of the following commands on Windows platform.
Clean the "AppData\Local\Temp" folder.
In search of windows type %temp%. then clean the folder.
Then try restarting Jenkins.
use java -jar jenkins.war --httpPort=8080 in cmd fo windows.
otherwise change the Port number.
java -jar jenkins.war --httpPort=8090
It worked for me!
1) Click "Start" button
2) Find and right-click Command Prompt. Then choose Run as administrator.
3) Execute the command "net stop jenkins" and "net start jenkins"
This will definitely works.
On windows, goto Run-> type "cmd" and navigate to your jenkins installation path.
Then perform the following list of commands:
To stop the jenkins:
jenkins.exe stop
To start the jenkins:
jenkins.exe start
To restart the jenkins:
jenkins.exe restart
Note:if you get an error then run the command as administrator..
Hope this will be helpful..

How to Run Appium Server and Android Emulator in Parallel through Shell Script in Jenkins?

I want to start Appium server for automated testing in Jenkins and start Emulator through commandline. When I start Appium through Appium start script in shell command in jenkins build step, Appium server initiates and run correctly.
But, the problem is I need to Initiate the Android Emulator by using same shell script. Since Appium server runs in background the next shell command to initiate the emulator does not affect and the jenkins build fails. So I need to run Appium server and Android Emulator in parallel through Shell Script in Jenkins build step.
Please provide solution to run both the scripts in parallel.
I made the Appium server and Android Emulator to run parallely through shell script in Jenkins build step.
I execute the following in Shell script and succesfully run my automation test.
#!/bin/sh
echo Start Emulator and Appium:
emulator -avd Test -noaudio -no-boot-anim -no-snapshot-load -no-snapshot-save -no-window &
appium &
sleep 2m
The sleep command made the command to sleep or wait for the initialisation of emulator and appium server detects the device parallely.
Maybe use parallel, like for instance:
node{
stage('Tests') {
parallel(appium: {
//first script
}, emulator: {
//second script
})
}
}

Cancelling Jenkins Job from Command line (CLI)

Just like 'build' command is used to start a job from Jenkins CLI, is there a way to cancel a long running job using CLI or any other command line technique. This I am trying in a windows machine and I am not looking to directly kill the process from task manager or shut down the jenkins.
Please suggest.
You can stop a Jenkins execution by calling JOB_URL/lastBuild/stop
Jenkins built-in Command Line tool does not provide a way to cancel/stop/abort a running build. But fortunately jenkins has provided other script API like Python API and Ruby API which have such ability.
Python API
class jenkinsapi.build.Build(url, buildno, job, depth=1)
stop()
Stops the build execution if it’s running :
return boolean True if succeded
False otherwise or the build is not running
API Link:https://jenkinsapi.readthedocs.org/en/latest/build.html
Ruby API
Class: JenkinsApi::Client::Job
#stop_build(job_name, build_number = 0) ⇒ Object (also: #stop, #abort)
Stops a running build of a job This method will stop the current/most recent build if no build number is specified.
API Link: http://www.rubydoc.info/gems/jenkins_api_client/1.4.2/JenkinsApi/Client/Job
This option assumes you have access to the Jenkins installation.
In Jenkins >2.195 you can do this using the Jenkins CLI jar:
# Export JENKINS_URL or add -s http://localhost[:port]/path/to/jenkins to the commands
export JENKINS_URL=http://localhost:8080/jenkins
# Get the name of the job you want to cancel
java -jar /path/to/jenkins-cli.jar -auth user:secret list-jobs
# Cancel the job
java -jar /path/to/jenkins-cli.jar -auth user:secret stop_builds <job_name>
# You can also disable the job, if needed
java -jar /path/to/jenkins-cli.jar -auth user:secret disable_job <job_name>

Jenkins: How to configure a always running server in a multijob scenario?

I am new to jenkins and trying to configure a server-client scenario using Multijob plugin.
So here's how it should go :
Phase 1: Compilation of the code.
In this one a separate project runs in which only compilation shell command is given
Phase 2: Running of Server
In this one a shell command project is given to run the server
Phase3 : Running of Client
In this one the client command should run
PROBLEM FACED : The project gets paused as the phase 2 never ends (with fail or success). As the server is always running one.
I tried giving the running of client parallel in phase 2 as a diff job but with that sometimes client job starts running before server job. Moreover I have multiple client jobs so it would be wise to create a different phase for them.
Can somebody please help me with the issue.
As phase 2 runs a shell command, I assume the server is running on Linux. Put an ampersand character after the server run command to put the process in background:
run_server &
and phase 2 will complete as soon as the server is launched. You'll probably also want to send the server's console output to a file, e.g.
run_server > server.log 2>&1 &
(the 2>&1 sends stdout and stderr output to the same file)

Resources