SLN
SLN

Reputation: 5082

Unable to find SBT in Jenkins while the plugin is installed

I've installed the sbt plugin for Jenkins under the global tool configuration. But Jenkins tells me it can't find the sbt command when I run my build

the Jenkinsfile

#!/usr/bin/env groovy

pipeline {
    agent any
    stages {
        stage('Build Image') {
            steps {
                echo "Build Image"
                sh 'sbt buildDockerImage'
            }
        }
    }

}

Error message;

 [Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Build Image)
[Pipeline] echo
Build Image
[Pipeline] sh
+ sbt buildDockerImage
/var/jenkins_home/workspace/App-ImageBuild@tmp/durable-1de2b2d2/script.sh: line 1: sbt: command not found
09:01:18.926552 durable_task_monitor.go:63: exit status 127

Anyone know why?

Upvotes: 1

Views: 1393

Answers (2)

aliShey
aliShey

Reputation: 28

For a quick fix
First, find the absolute path for sbt in your machine

 which sbt

/usr/local/bin/sbt

Then, add the full path to groovy script:

sh '/usr/local/bin/sbt buildDockerImage'

Upvotes: 0

Marat
Marat

Reputation: 161

I would first delete #!/usr/bin/env groovy since you are using declarative pipeline, not a scripted one.

Second, the issue is that the tool is being installed by Jnekins in it's home directory which is not included in the PATH environment variable. As such, you should specify the full path to sbt executable:

steps {
    echo "Build Image"
    sh "${tool name: 'mySbt', type: 'org.jvnet.hudson.plugins.SbtPluginBuilder$SbtInstallation'}/bin/sbt  buildDockerImage"
}

replace 'mySbt' with the name you specified at Global Tools Configuration page.

As an alternative solution, you can just add sbt dir to PATH env var by adding following block:

environment {
     SBT_HOME="${tool 'mySbt'}"
     PATH="${env.SBT_HOME}/bin:${env.PATH}"
}

replace 'mySbt' with the name you specified at Global Tools Configuration page.

Upvotes: 1

Related Questions