Here's how we've done it: Launch appium, Save the PID, and add a trap statement to terminate the process on interrupt/script end. You can put this in "Execute Shell" build step before your test runs. See sample shell script below
---------------
#Start appium server
appium_log=appium.log
appium_cmd="node <REPLACE_WITH_APPIUM_PATH>/appium/lib/server/main.js"
echo "[INFO] Appium command: $appium_cmd"
$appium_cmd &> $appium_log&
appium_pid=$!
#check if appium was successfully started
sleep 1
appium_pid_start=`ps -p $appium_pid | grep node | awk '{ print $1 }'`
if [ -z $appium_pid_start ] ; then
echo "[ERROR] Appium failed to start! Port $appiumport may be already in use. "
exit 1
fi
echo "[INFO] Appium started with pid: $appium_pid . Logging to: ${appium_log}"
# be sure to kill appium on script stop
trap "kill $appium_pid" SIGINT SIGTERM EXIT
[EnvInject] - Loading node environment variables.
Building in workspace /Users/SWQA/Desktop
[Desktop] $ /bin/sh -xe /Users/Shared/Jenkins/tmp/hudson1354756946659329446.sh
+ appium_log=appium.log
+ appium_cmd='node /usr/local/bin/appium/lib/server/main.js'
+ echo '[INFO] Appium command: node /usr/local/bin/appium/lib/server/main.js'
[INFO] Appium command: node /usr/local/bin/appium/lib/server/main.js
+ appium_pid=361
+ sleep 1
+ node /usr/local/bin/appium/lib/server/main.js
++ ps -p 361
++ grep node
++ awk '{ print $1 }'
+ appium_pid_start=
+ '[' -z ']'
+ echo '[ERROR] Appium failed to start! Port may be already in use. '
[ERROR] Appium failed to start! Port may be already in use.
+ exit 1
Build step 'Execute shell' marked build as failure
Finished: FAILUREApart from that, when i try to run my env.rb from jenkins shell there are errors regarding the requires that i have on the file such as: 'require rspec' and 'require selenium-webdriver'. The error tells me that "no such file to load" and as so nothing more is done. However i have these gems installed. When i run the tests (feature and env.rb) from my console everything works correctly.
How can i resolve this on jenkins?
Can you help me on this?
Thanks