Jsonnet

Drone supports Jsonnet scripting as an alternate to yaml configurations. Jsonnet is a data templating language that extends Json syntax, adding constructs for generating, translating and refining data.

Jsonnet Language Specification

Jsonnet is intended for projects with complex configurations that benefit from advanced scripting capabilities and code re-use.

Usage

In order to use Jsonnet configuration files your system administrator must enable Jsonnet support for your Drone server.

You can use Jsonnet for an individual project by creating a .drone.jsonnet file in the root of your git repository. Then update your repository configuration file accordingly, from your repository settings screen.

Example

Here is an example script that returns a pipeline configuration. Please note the returned pipeline object uses the same structure as a pipeline defined in yaml.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
{
    "kind": "pipeline",
    "type": "docker",
    "name": "default",
    "steps": [
        {
            "name": "build",
            "image": "alpine",
            "commands": [
                "echo hello world",
            ]
        }
    ]
}

Tooling

You can automatically convert your Jsonnet configuration file to yaml using the command line tools. This can be useful for local testing.

$ drone jsonnet --stdout

kind: pipeline
name: default

steps:
- name: build
  image: alpine
  commands: [ echo hello world ]

Common Problems

The below error may indicate that Drone does not recognize your configuration as a jsonnet file. The most common root cause for this problem is when you forget to enable jsonnet in your Drone server settings.

yaml: line 1: mapping values are not allowed in this context

The second most common root cause for this issue is when you forget to rename your file with a jsonnet extension. Drone assumes configuration files are written in yaml unless you explicitly use the jsonnet file extension.