Run Robot + AppliumLibrary on jenkins, mac env

I got jenkins run on mac with brew install. Setup robot and appiumlibrary in virtualenv, use npm install appium. I can run robot script on command line against android emulator, smoothly. But when i put those steps to jenkins. Jenkins can start appium and can bring up android emulator. but it seem like robot script cannot open application. Mostly I got this

Show intro as landing page [debug] e[35m[HTTP]e[39m Request idempotency key: d00f1d6c-48d5-4b93-8d71-581d645aa94d
[ WARN ] Keyword ‘Capture Page Screenshot’ could not be run on failure: No application is open
| FAIL |
ProtocolError: (‘Connection aborted.’, RemoteDisconnected(‘Remote end closed connection without response’))


This is how robot script run

*** Settings ***
Library AppiumLibrary

*** Variables ***
${URL} http://127.0.01:4723/wd/hub
${PLATFORM} Android
${DEVICE_TARGET} 12.0
${DEVICE_NAME} emulator-5554
${APP_LOCATION} app.apk

*** Keywords ***
Open Pixel
Open Application ${URL}
… platformName=${PLATFORM}
… platformVersion=${DEVICE_TARGET}
… deviceName=${DEVICE_NAME}
… app=${APP_LOCATION}
… automationName=UIAutomator2

This is my jenkins step

step 1

appium &
sleep 10

step 2

~/Library/Android/sdk/emulator/emulator -avd machine-B -no-audio -no-snapshot -wipe-data &
until ~/Library/Android/sdk/platform-tools/adb wait-for-device shell getprop init.svc.bootanim | grep -m 1 stopped; do
echo “Waiting…”
sleep 1
done

step 3

#!/bin/bash --login -x
export ANDROID_SDK_ROOT=~/Library/Android/sdk &
export PATH=“$ANDROID_SDK_ROOT:$PATH” &
source venv-robot/bin/activate &
venv-robot/bin/robot demo.robot

Welcome any suggestions :bowing_man:

Try logging into the server as the jenkins user and running the scripts by hand, exactly as your job would run. Add debug statements, especially for Environment Variables to make sure you are getting everything you need in your non-interactive bash login shell. Finally, check the logs of your emulator and of Appium server.

Posting the full log of Appium server as a git gist (https://docs.github.com/en/get-started/writing-on-github/editing-and-sharing-content-with-gists/creating-gists) would be very helpful.