Send module version as command line argument to SB

2020-03-04 09:41发布

I am using TeamCity to run a bash script that is utilizing SBT Native Packager to publish an image to Docker. The sbt portion of the bash script looks something like this:

sbt -DdockerRepository=$repo -DpackageName=$packageName -D myproject/docker:publish

I want to pass on the TeamCity build number as a version number to my package. Today I specify the version number manually in settings in build.sbt:

settings(
  version := "0.20",
  ....,
  dockerBaseImage := "example.com:5000/linux/java8:latest",
  dockerRepository in Docker := Some("example.com/myoldrepo"),
  dockerUpdateLatest := true'
)

I want to be able to do it like this:

activator -Dversion=0.21 -DpackageName=myproject -D myproject/docker:publish

but this does not seem to work. Yet overriding the dockerRepository like I do above is working.

How can I pass my desired version number into SBT from the command line/TeamCity?

2条回答
三岁会撩人
2楼-- · 2020-03-04 09:54

Try something like this:

val myVersion = util.Properties.propOrNone("version").getOrElse("0.20")

val myDockerBaseImage = util.Properties.propOrNone("dockerBaseImage").
                    getOrElse("example.com:5000/linux/java8:latest")

lazy val myProject = Project("myProject",file("path")).settings(
  version := myVersion,
  dockerBaseImage := myDockerBaseImage,
  ....,
  dockerRepository in Docker := Some("example.com/myoldrepo"),
  dockerUpdateLatest := true
)

And then call it (depends on your sbt installation):

SBT_OPTS="-Dversion=0.21" sbt

sbt -Dversion=0.21

activator -Dversion=0.21

查看更多
虎瘦雄心在
3楼-- · 2020-03-04 10:13

You could set version before publish:

sbt 'set version := "1.0"' docker:publish
查看更多
登录 后发表回答