command fails on jenkins, but works on terminal

1.8k views Asked by At

I'm working on using fastlane screengrab/snapshot to take screenshots of my android and ios app. When I run them locally on terminal, they work perfectly, but when I run them from jenkins, they fail. I'm using macOS.
Android:

/Users/shared/Library/Android/sdk/tools/emulator -avd Pixel_API_22 &
fastlane screengrab

(These 2 are in a .sh)

The first line failed: PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

iOS:

fastlane snapshot

it failed while trying to build a test because of an provisioning profile error:

xcodebuild -showBuildSettings -scheme UITests -project ./abc.xcodeproj

(this is a command that fastlane snapshot execute automatically)

Again, they both run smoothly on terminal (I ran them in the same workspace as junkins)

2

There are 2 answers

6
VonC On BEST ANSWER

Double-check the environment settings after executing your job in Jenkins: you might see differences with the same environment settings as seen with your user account in command-line (where it is working)

The username might be different (if your Jenkins server/agent runs with another account).

The OP Son Nguyen confirms the PATH issue:

the developer who set up jenkins put a wrong path to android sdk, so I was able to run the android part by fixing the path.

And the OP adds:

fastlane was installed in /usr/local/bin while jenkins was in /User/myUser: So, somehow they didn't work well together.
I reinstalled fastlane in /User/myUser and it worked.

0
Vijay Chandamala On

This got it working for me.

I had to include this at the top of my script :

     #!/bin/zsh
     source ~/.zshrc

and my .zshrc had this:

    export PATH="$PATH:"/usr/local/bin/
    export SSL_CERT_FILE=/etc/ssl/cert.pem # for openssl error
    export ANDROID_HOME=/Users/jenkins/Library/Android/sdk