Automations: Conditional Params or other strategies for multi-env

Migrating our org to spaces and have it mostly working, but now looking to reduce duplication.

We have multiple environments (prod/dev/demo etc) which ultimately are just docker images and use ArgoCD to manage deployments.

It's all working, but we have to have a build for each environment which is a lot of duplication.

Any suggestions to clean this up? I was thinking:

  • If we could set params per branch, that would solve it (if dev, set ‘server’ to dev)
  • Some sort of templating support but I don't think that exists?



Hi Dustin ,

We have a task in the backlog to implement templates in Space Automation. Unfortunately, there is no ETA on it yet. Feel free to follow the updates here:

Currently, there is another solution that should work for this case. Space Automation allows the use of external libraries hosted in a Maven repository. Thus, you can create and public a Maven library containing the jobs/steps/any Kotlin code to reuse in different .space.kts files or recall it:

As for setting parameters per branch, the `kotlinScript` can be used to create a set of parameters with stable names and assign project values dynamically. The “{{run:git-checkout.ref}}” parameter can be used here:

Here is a short sample of a similar conditions:

job("Build") {
	host {
		kotlinScript { api ->
			if (api.parameters["env"] == "dev") {
				api.parameters["target-url"] = Ref("project:dev-target-url")
				api.secrets["target-password"] = Ref("project:dev-target-password")
			} else {
				api.parameters["target-url"] = Ref("project:prod-target-url")
				api.secrets["target-password"] = Ref("project:prod-target-password")

	host {
		shellScript {
			env["URL"] = "{{ target-url }}"
			env["PASSWORD"] = "{{ target-password }}"

Thanks so much @... this is perfect! Happy Holidays!


Please sign in to leave a comment.