1

I try to solve the following issue:

job("Docker | deploy") {
    docker {
        build {
            context = "docker"
            file = "./docker/Dockerfile"
            labels["vendor"] = "mycompany"
            args["HTTP_PROXY"] = "http://10.20.30.1:123"
        }

        push("registry.com") {
            versionOne = Params("version-one")
            versionTwo = Params("version-two")
            
            tag = "${'$'}versionOne-${'$'}versionTwo"
        }
    }
}

Within the push step, the tag should be combined of versionOne and versionTwo dynamically, but I don't figured it out how to achieve this.

Does someone know how to use variables dynamically in a space automation script?

Joffrey
  • 32,348
  • 6
  • 68
  • 100
andreas.teich
  • 789
  • 1
  • 12
  • 22

2 Answers2

1

The correct way to do it below:

job("Docker | deploy") {
    env["VERSION_ONE"] = Params("version-one")
    env["VERSION_TWO"] = Params("version-two")

    docker {
        build {
            context = "docker"
            file = "./docker/Dockerfile"
            labels["vendor"] = "mycompany"
            args["HTTP_PROXY"] = "http://10.20.30.1:123"
        }

        push("registry.com") {
            tags("${'$'}VERSION_ONE-${'$'}VERSION_TWO")
        }
    }
}
Mikhail Kadysev
  • 103
  • 1
  • 10
0

The docker DSL is now deprecated. Instead, use the dockerBuildPush DSL in a host step (instead of a docker/kaniko step).

Also, for regular project parameters (not secrets), you can use the {{ project:<param> }} template syntax instead of going through environment variables:

job("Docker | deploy") {    
    host {
        dockerBuildPush {
            context = "docker"
            tags {
                +"registry.com/image:{{ project:version-one }}-{{ project:version-two }}"
            }
        }
    }
}
Joffrey
  • 32,348
  • 6
  • 68
  • 100