Config

This is the reference of the agola config file format.

Config file formats

The accepted syntaxes are (checked in this order):

  • jsonnet (.agola/config.jsonnet)
  • yaml (.agola/config.yml)
  • json (.agola/config.json)

The config file is quite simple with just some syntactic sugar for easier definitions of some task steps.

For basic configs you would prefer to use the yml syntax but for more complex configs we suggest to use the jsonnet syntax (see the examples).

Instead of adding some templating facilities to yaml that will always leave some open unsupported cases and add much more complexity we choosed to push the use of jsonnetRun Configuration Reference - 图1 .

jsonnet helps writing a parametrizable and easy to maintain config. See the below matrix build example.

Generating a config with jsonnet keeps the principle of reproducible runs since a jsonnet file will always produce the same output.

You’re also free to use you own way to generate the config file. Just commit the final result to git.

Global

OptionTypeDescription
versionStringConfig version
runsList: RunRuns definitions

Version

The config file version. Currently only v0.

Runs

Run

OptionTypeDescription
nameStringRun name
tasksList: TaskRun tasks
whenWhenConditions to match to execute this run. If the conditions aren’t met then the run is skipped
docker_registries_authMap: RegistryHost(String) => DockerRegistryAuth(DockerRegistryAuth)Docker registries authentication data

Task

OptionTypeDescription
nameStringTask name
runtimeRuntimeRuntime definition
stepsList: StepSteps definitions
environmentMap: EnvVarName(String) => EnvVarValue(Value)Environment variables to set
working_dirStringThe working dir where the steps will be executed (defualt: ~/project)
shellStringShell to use (defaults to /bin/sh -e)
userStringThe user id or username to use when executing the task steps
ignore_failureBooleanDon’t mark the run as failed if this task is failed
approvalBooleanIf true the task must be approved before it can start
dependsList: DependList of task dependencies and conditions
whenWhenConditions to match to execute this task. If the conditions aren’t met then the task is skipped
docker_registries_authMap: RegistryHost(String) => DockerRegistryAuth(DockerRegistryAuth)Docker registries authentication data
Depend
OptionTypeDescription
taskStringTask name
conditionsList: ConditionList of conditions to satisfy. If no condition is satisfied the task will be skipped. Possible conditions are: on_success, on_failure, on_skipped

It’s also available a short form for specifying a dependency (simpler when using yaml):

  1. depends:
  2. - task 01 # depends on task 01 with default condition on_success
  3. - task 02: # depends on task 02 with conditions on_failure, on_skipped
  4. - on_failure
  5. - on_skipped
Step
OptionTypeDescription
TypeStringStep type

There are different types of steps:

  • clone: clones and checkouts (to the right commit sha) code
  • run: executes e command
  • save_to_workspace: save in the run workspace the specified files/dirs
  • restore_workspace: restores the run workspace in the specified dir
  • save_cache: save some contents in a project cache key.
  • restore_cache: restores contents from a project cache.

Every step can have a short form (simpler when using yaml) or a normal form:

  • Short form:
  1. $stepname: $stepdefinition

Examples:

  1. run:
  2. name: "run step"
  3. command: "echo something"
  • Normal form:
  1. type: $steptype
  2. $otherstep fields

Examples:

  1. type: run
  2. name: "run step"
  3. command: "echo something"
clone
  • Short form:
  1. clone:

clone clones and checkouts (to the right commit sha) code.

  • Long form:
OptionTypeDescription
depthIntClones with —depth <n> parameter (defaults to nil)
recurse_submodulesBoolClones with —recurse-submodules parameter (defaults to false)
run
  • Short form:
  1. run: command

The command must be a one line command In this case the run step name will be the same of the command trimmed at the maximum name size.

  • Long form:
OptionTypeDescription
nameStringStep name. Required when the command is multiline. If not provided will be the same of the command trimmed at the maximum name size
commandStringCommand to run
environmentMap: EnvVar Name(String) => EnvVar Value(String)Environment variables to set
working_dirStringThe working dir where the steps will be executed
shellStringShell to use (defaults to /bin/sh -e)
ttyBoolUse a pseudo terminal for command execution (defaults to true)
save_to_workspace
OptionTypeDescription
contentsList: contentContents to save in the workspace

content

OptionTypeDescription
source_dirStringSource dir where to take the files to save
dest_dirStringWorkspace destination dir where to save the files
pathsList: StringContents to save in the workspace. Every path accepts the ** (doublestar) notation to match all the subchilds
restore_workspace
OptionTypeDescription
dest_dirStringDestination dir where to restore the workspace
save_cache
OptionTypeDescription
contentsList: contentContents to save in the workspace

content

OptionTypeDescription
keyStringCache key to save. It’s a template to dynamically generate cache keys based on runtime data. See caching
source_dirStringSource dir where to take the files to save
dest_dirStringWorkspace destination dir where to save the files
pathsList: StringContents to save in the workspace, if empty all the files inside source_dir will be saved. Every path accepts the ** (doublestar) notation to match all the subchilds
restore_cache
OptionTypeDescription
keysList of StringList of cache key to restore. Every entry is a template to dynamically generate cache keys based on runtime data. See caching. They’ll tried in order until a match by prefix of an existing cache key is found, the newest matching key will be restored
dest_dirStringDestination dir where to restore the cache

Runtime

OptionTypeDescription
typeStringRuntime Type (currently only pod is supported)
archStringArchitecture (valid architectures are: 386 amd64 arm arm64)
containersList: ContainerA list of containers, the first container will be the one where the tasks steps will be executed. Other containers may be defined to provide services needed for the task (a database etc…)
Container
OptionTypeDescription
imageStringImage to use
environmentMap: EnvVarName(String) => EnvVarValue(Value)Environment variables to set
working_dirStringWorking dir where the entrypoint will be executed (also used for steps in a task)
userStringThe user id or username to use when executing the entrypoint or the task run steps
volumesList: VolumeA list of volumes (currently only tmpfs is supported)
privilegedBoolGive extended privileges to this container (defaults to false). Executors config must have allowPrivilegedContainers set to true
Volume

Containers can mount one or more volumes (currently only tmpfs is supported).

OptionTypeDescription
pathStringMountpoint
tmpfsTmpFS Volumetmpfs volume

Example of single volume with size limit:

  1. - image: image01
  2. volumes:
  3. - path: /mnt/tmpfs
  4. tmpfs:
  5. size: 1Gi

Example with two volumes, the former with a size limit and the latter without:

  1. - image: image01
  2. volumes:
  3. - path: /mnt/vol1
  4. tmpfs:
  5. size: 512Mi
  6. - path: /mnt/vol2
  7. tmpfs: {}
TmpFS Volume
OptionTypeDescription
sizeStringFilesystem size

Additional types

When

When represent a set of conditions to match

OptionTypeDescription
branchString, List of String or map with keys include/excludeMatch a branch with the specified conditions
tagString, List of String or map with keys include/excludeMatch a tag with the specified conditions
refString, List of String or map with keys include/excludeMatch a ref with the specified conditions

The value provided to branch/tag/ref can be different:

  • A string
  • A list of strings
  • A map with keys include and exclude and values string or list of string (like above). In this way the branch/ref/tag must be included and not excluded

The provided strings can be a simple string (the value must match that string) or a regular expression (when enclosed in / or #)

Example

  1. runs:
  2. - name: run01
  3. tasks:
  4. - name: task01
  5. when:
  6. branch: master
  7. tag:
  8. - v1.0
  9. - /v1\..*/
  10. ref:
  11. include: master
  12. exclude: [ '#/refs/pull/.*#' , /refs/heads/branch01 ]

The task task01 will be executed only if:

  • we are on a branch with value master
  • we are on a tag with value v1.0 or that matches the regexp v1\..* (i.e v1.0, v1.2 but not v10 or v2)
  • we are on a ref that match the regexp /refs/pull/.* or the value “/refs/heads/branch01`

Value

A value that can be defined as a string or from a project variable

As a string

  1. password: yoursecretpassword

As a project variable

  1. password:
  2. from_variable: yoursecretpassword

Docker Registry Auth

OptionTypeDescription
typeStringRegistry authentication type: basic (default) or encodeauth only default is supported)
usernameValueRegistry username. Can be a string or from a variable
passwordValueRegistry password. Can be a string or from a variable
authValueRepresents and encoded auth string like the one used in the docker config.json. Can be a string or from a variable

Examples

yaml config

  1. version: v0
  2. runs:
  3. - name: agola example go run
  4. tasks:
  5. - name: build go 1.12
  6. runtime:
  7. type: pod
  8. arch: amd64
  9. containers:
  10. - image: golang:1.12-stretch
  11. environment:
  12. GO111MODULE: "on"
  13. steps:
  14. - clone:
  15. - restore_cache:
  16. keys:
  17. - cache-sum-{{ md5sum "go.sum" }}
  18. - cache-date-
  19. ## golang image sets GOPATH to /go
  20. dest_dir: /go/pkg/mod/cache
  21. ## This will create a binary called `agola-example-go` under ./bin
  22. - run:
  23. name: build the program
  24. command: go build .
  25. ## Copy the built binary to the workspace
  26. - save_to_workspace:
  27. contents:
  28. - source_dir: .
  29. dest_dir: /bin/
  30. paths:
  31. - agola-example-go
  32. - save_cache:
  33. key: cache-sum-{{ md5sum "go.sum" }}
  34. contents:
  35. - source_dir: /go/pkg/mod/cache
  36. - save_cache:
  37. key: cache-date-{{ year }}-{{ month }}-{{ day }}
  38. contents:
  39. - source_dir: /go/pkg/mod/cache
  40. - name: run
  41. ## This task will run the built binary in the parent task and leverages the workspace capabilities
  42. runtime:
  43. type: pod
  44. arch: amd64
  45. containers:
  46. - image: debian:stretch
  47. steps:
  48. - restore_workspace:
  49. dest_dir: .
  50. - run: ./bin/agola-example-go
  51. depends:
  52. - build go 1.12

jsonnet config

This is an example jsonnet config the creates a build matrix between go version and architecture.

It generates 4 “go build” with the different combinations.

  1. local go_runtime(version, arch) = {
  2. type: 'pod',
  3. arch: arch,
  4. containers: [
  5. { image: 'golang:' + version + '-stretch' },
  6. ],
  7. };
  8. local task_build_go(version, arch) = {
  9. name: 'build go ' + version + ' ' + arch,
  10. runtime: go_runtime(version, arch),
  11. working_dir: '/go/src/github.com/sorintlab/agola',
  12. environment: {
  13. GO111MODULE: 'on',
  14. },
  15. steps: [
  16. { type: 'clone' },
  17. { type: 'restore_cache', keys: ['cache-sum-{{ md5sum "go.sum" }}', 'cache-date-'], dest_dir: '/go/pkg/mod/cache' },
  18. { type: 'run', name: 'build the program', command: 'go build .' },
  19. { type: 'save_to_workspace', contents: [{ source_dir: '.', dest_dir: '/bin/', paths: ['agola-example-go'] }] },
  20. { type: 'save_cache', key: 'cache-sum-{{ md5sum "go.sum" }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },
  21. { type: 'save_cache', key: 'cache-date-{{ year }}-{{ month }}-{{ day }}', contents: [{ source_dir: '/go/pkg/mod/cache' }] },
  22. ],
  23. };
  24. {
  25. runs: [
  26. {
  27. name: 'agola build/test',
  28. tasks: [
  29. task_build_go(version, arch)
  30. for version in ['1.11', '1.12']
  31. for arch in ['amd64', 'arm64']
  32. ] + [
  33. {
  34. name: 'run',
  35. runtime: {
  36. type: 'pod',
  37. arch: 'amd64',
  38. containers: [
  39. { image: 'debian:stretch' },
  40. ],
  41. },
  42. steps: [
  43. { type: 'restore_workspace', dest_dir: '.' },
  44. { type: 'run', command: './bin/agola-example-go' },
  45. ],
  46. depends: [
  47. 'build go 1.12 amd64',
  48. ],
  49. },
  50. ],
  51. },
  52. ],
  53. }