Space Automation automation Help


We suppose two main CI/CD scenarios for Docker:

  • Simple automated Docker builds: All image dependencies already exist and all you need is to build and publish a Docker image.

  • Complex scenarios: An Automation job must create image dependencies before building and publishing the image.


  • You have already defined the Docker image with a Dockerfile stored in the project's repository.

Build and publish a Docker image

For example, the job below first builds and then publishes the image defined in the Dockerfile located in the project's docker directory.

job("Build and push Docker") { docker { build { context = "docker" file = "./docker/Dockerfile" args["HTTP_PROXY"] = "" labels["vendor"] = "mycompany" } push("") { tag = "version1.0" } } }
  • docker: is a special step used to build and publish Docker images. In fact, it's a special type of container with Docker on board.

  • build: runs the docker build command with the following arguments

  • push: runs the docker push command with the following arguments

    • "": image name including the repository URL. Note that to be able to push to a Space Packages Container registry, your script doesn't require authentication.

    • tag: specifies the image tag.

Create an image dependency, build, and publish a Docker image

Quite often, you may need to first generate some artifact (say, a .jar file) and then put it into an image. Such cases require running two steps: The first generates the artifact and the second one runs docker build and docker push.

job("Build and push Docker") { container("openjdk") { shellScript { content = """ ./gradlew build cp output mnt/space/share """ } } docker { beforeBuildScript { content = "cp mnt/space/share docker" } build { context = "docker" } push("") { tag = "version1.0" } } }
  • The container step uses gradlew build to generate some artifacts and put them to the file share.

  • In the docker step:

    • beforeBuildScript is a sub-step that runs before build. Here we use beforeBuildScript to copy the Gradle output from the file share to the context directory.

    • build and push build and push the image correspondingly.

Last modified: 27 July 2020