I publish to an internal Nexus repository. We have two repos, "dev" and "production". Developers use the dev repo, the build team uses the production repo which they access from machines in a secure area. I would like to add an environment variable or SBT config that defines STAGE with a default value of "dev". On the production build boxes STAGE would be overriden to "production". How can I do this? I am able to define stage in my build.sbt file and use it in the publishTo task, I just can't figure out how to get the value from the environment. Here is what I have.
val stage = settingKey[String]("stage")
stage := "dev"
publishTo <<= (version, stage) { (v: String, s: String) =>
val nexus = "http://my-internal-nexus:8081/nexus/content/repositories/"
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + s + "-snapshots-m2")
else
Some("releases" at nexus + s + "-releases-m2")
}
On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.
To set (or change) a environment variable, use command " set varname=value ". There shall be no spaces before and after the '=' sign. To unset an environment variable, use " set varname= ", i.e., set it to an empty string.
You can pass stage in a system property and read it into a setting:
stage := sys.props.getOrElse("stage", default = "dev")
Use sbt -Dstage=production
to pass this in your build environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With