Home > Blockchain >  Jenkins pipeline job executing commands in tmp folder
Jenkins pipeline job executing commands in tmp folder

Time:09-14

MacOS Monterey version 12.4

I'm trying to run a simple pipeline script on my jenkins job

   pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh('emulator -list-avds')
            }
        }
    }

But it throws an error:

/Users/<my_username>/.jenkins/workspace/<my_job_name>@tmp/durable-22217e91/script.sh: line 1: emulator: command not found

My question is: why is it executing commands in the tmp folder? Anything "emulator" related does work when I run commands via terminal.

Following this answer, I've confirmed I'm in the correct dir Why Jenkins mounts a temporary volume in addition to the workspace?

CodePudding user response:

You are getting this error because the emulator executable is not set in the PATH. Try something like the below.

Try setting your PATH variable to add emulator executable.

environment {
   PATH = "/PATH_EMULATOR/bin:${env.PATH}"
}

or something like the below.

  withEnv(["PATH EMULATOR=/PATH_EMULATOR/bin"]) {
    sh('emulator -list-avds')
  }

or you can also use the full qualified path to the executable

sh('/PATH_TO_EMULATOR/bin/emulator -list-avds')
  • Related