• Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Major Major
    • sbt-plugin
    • None
    • 87.v455263c57692

      There is support in the tools element of the pipeline declarative DSL for both gradle and Maven, however there appears to be presently no equivalent support for Scala's SBT.

          [JENKINS-42475] Support SBT in declarative pipeline builds

          This would be a great improvement to have.  At the moment, if you're using the pipeline DSL for an SBT project, the options that I'm aware of are:

          In my view this lack of compatibility between Jenkins fundamentals, forcing hackery such as the examples above, is really discouraging to wider adoption of the pipeline DSL.

          Oliver Lockwood added a comment - This would be a great improvement to have.  At the moment, if you're using the pipeline DSL for an SBT project, the options that I'm aware of are: something like what's described in this Gist: https://gist.github.com/muuki88/e2824008b653ac0fc5ba749fdf249616 something really horrible, like def SBT = 'java -Dsbt.log.noformat=true -jar `find ~/tools/ -executable -type f -name "sbt-launch.jar"` sh "${SBT} compile test" In my view this lack of compatibility between Jenkins fundamentals, forcing hackery such as the examples above, is really discouraging to wider adoption of the pipeline DSL.

          david crosson added a comment - - edited

          in scripted pipeline, it is possible to write :

           
          node {
            def sbtHome = tool 'sbt-0.13.15'
            def sbt = "${sbtHome}/bin/sbt -no-colors -batch"
            stage('build') {
              sh "${sbt} clean assembly"

          ...

           I'm just going to make some experiments with declarative pipelines...

          david crosson added a comment - - edited in scripted pipeline, it is possible to write :   node {   def sbtHome = tool 'sbt-0.13.15'   def sbt = "${sbtHome}/bin/sbt -no-colors -batch"   stage('build') {     sh "${sbt} clean assembly" ...  I'm just going to make some experiments with declarative pipelines...

          david crosson added a comment - - edited

          OK I've found a way to use sbt within declarative pipelines :

          https://gist.github.com/dacr/a2576dee980c5c9bd29cf538a093ca72

           But it won't work with docker agent for example  as the sbt auto-installation feature is not available in the declarative pipeline context...

          david crosson added a comment - - edited OK I've found a way to use sbt within declarative pipelines : https://gist.github.com/dacr/a2576dee980c5c9bd29cf538a093ca72  But it won't work with docker agent for example  as the sbt auto-installation feature is not available in the declarative pipeline context...

          Andrew Bayer added a comment -

          FYI, the tool auto-install doesn't work in docker.image.inside whether in Declarative or Scripted. Anyway, this needs the sbt plugin to add a @Symbol.

          Andrew Bayer added a comment - FYI, the tool auto-install doesn't work in docker.image.inside whether in Declarative or Scripted. Anyway, this needs the sbt plugin to add a @Symbol .

          Sion Williams added a comment - - edited

          Here's what I do in declarative mode:

          pipeline {
              ...
              environment {
                SBT_HOME = tool name: 'sbt.13.13', type: 'org.jvnet.hudson.plugins.SbtPluginBuilder$SbtInstallation'
                PATH = "${env.SBT_HOME}/bin:${env.PATH}"
              }
              ...
          }
          

          A call to sbt can be as simple as

          sh 'sbt test'
          

          Sion Williams added a comment - - edited Here's what I do in declarative mode: pipeline { ... environment { SBT_HOME = tool name: 'sbt.13.13' , type: 'org.jvnet.hudson.plugins.SbtPluginBuilder$SbtInstallation' PATH = "${env.SBT_HOME}/bin:${env.PATH}" } ... } A call to sbt can be as simple as sh 'sbt test'

          I'm able to utilize sbt in a declarative pipeline pulling a docker image of sbt from the public registry (https://hub.docker.com/r/hseeberger/scala-sbt/) as the agent: 

          pipeline {
              agent {
                  docker {
                      image 'hseeberger/scala-sbt'
                  }
              }
              stages {
                  stage('Test') {
                      steps {
                          echo 'Building..'
                          sh "sbt test"
                      }
                  }
              } 
          }

          immanuel Purushothaman added a comment - I'm able to utilize sbt in a declarative pipeline pulling a docker image of sbt from the public registry ( https://hub.docker.com/r/hseeberger/scala-sbt/ ) as the agent:  pipeline { agent { docker { image 'hseeberger/scala-sbt' } } stages { stage( 'Test' ) { steps { echo 'Building..' sh "sbt test" } } } }

          Craig Tataryn added a comment -

          I can confirm that sbt is able to be used as willis6 demonstrates above.

          Craig Tataryn added a comment - I can confirm that sbt is able to be used as willis6 demonstrates above.

            froque Filipe Roque
            keirlawson Keir Lawson
            Votes:
            10 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: