Configure SBT credentials on Cloudbees platform to publish artifacts

Damien published on
2 min

When you want to deploy your Scala artifacts (or anything else) with SBT, its reference documentation explains well how to configure your own repository's credentials.

Great, just create a bunch of *.sbt file in ~/.sbt folder. Easy, simple.

But wait, I'm trying to publish artifacts from a Cloudbees Jenkins instance. How can I copy my *.sbt files into `~/.sbt``on Cloudbees Jenkins platform? You can't.

On Cloudbees, all files handled by Jenkins come from either your SCM (GIT, SVN, ...) or from your private repository: /private/<my_account>/ (you can upload files in thanks to WebDAV).

As I want to load credentials in SBT, that is to say secret passwords, I want to the 2nd source.

Note: yes, I could have setup the following configuration in my build:

credentials += Credentials(file("/private/<my_account>/.credentials"))

But, you should avoid it for the next reasons:

  • your build is now platform-dependent
  • as this is a project's configuration, you have to duplicate it in all of your project

So it's much better to use *.sbt files to configure global credentials, but how to do it on Cloudbees ?

Create and upload your *.sbt file your private folder

I have chosen to copy all my *.sbt files into /private/<my_account>/.sbt folder.

Create a new shell script

Create this new shell script /private/<my_account>/bin/ with the following content:


mkdir -p ~/.sbt
for f in /private/<my_account>/.sbt/*.sbt
  ln -s $f ~/.sbt/
This script will create a symbolic link in `~/.sbt/` for each files found in `/private/<my_account>/.sbt`.
This will work regardless of the Jenkins slave selected by the master.

## Add a new Jenkins Job to excute the shell script

Before a SBT build which requires credentials (eg. for `publish` task), create a new Jenkins job :

/bin/sh /private/<my_account>/bin/

Save and run your job.

Voilà, that's all folks!