Skip to content

Expose custom executor services with $CI_JOB_SERVICES

What does this MR do?

It exposes job services with the CI_JOB_SERVICES variable, in JSON format. This only happens if there is at least one service defined. Otherwise the variable isn't set.

JSON has been chosen as the serialization format, because it removes headaches around the entrypoint / command arrays. For example jq can be used in the custom runner prepare.sh script, to parse the json in the following manner. However, any json parser can be used.

The input:

# gitlab-ci.yml

build:
  stage: some_stage
  services:
    - redis:latest
    - name: my-postgres:9.4
      alias: henk
      entrypoint: ["path", "to", "entrypoint"]
      command: ["path", "to", "cmd"]
  script:
    - // ...

The variable set:

$ printenv

CI_JOB_SERVICES=[{"name":"redis:latest","alias":"","entrypoint":null,"command":null},{"name":"my-postgres:9.4","alias":"henk","entrypoint":["path","to","entrypoint"],"command":["path","to","cmd"]}]

The array parsed:

$ echo $CI_JOB_SERVICES | jq '.[1]'

 {
   "name": "my-postgres:9.4",
   "alias": "henk",
   "entrypoint": [
     "path",
     "to",
     "entrypoint"
   ],
   "command": [
     "path",
     "to",
     "cmd"
   ]
 }

The name extracted:

$ echo $CI_JOB_SERVICES | jq '.[1].name'

"my-postgres:9.4"

Why was this MR needed?

There was no handy way to view the job services in the custom exporter. Therefore not being able to set them up in the prepare step of the custom executor. With the CI_JOB_SERVICES variable, these are exposed and therefore enabling more powerful custom executors to be created.

Are there points in the code the reviewer needs to double check?

As I have noted in 4358, golang is something I have never used and my C is kind of rusty. Therefore looking at things like code / gitlab conventions would be appreciated.

Does this MR meet the acceptance criteria?

  • Documentation custom executor updated
  • Added tests for this feature/bug
  • In case of conflicts with master - branch was rebased
  • Add changelog entry (bin/changelog is missing?)

What are the relevant issue numbers?

Closes #4358 (closed)

Followup

I'll write the documentation for a Podman/buildah custom executor which uses services, when this gets approved.

Edited by Georgi N. Georgiev

Merge request reports