Skip to content

Ci integration - #236

Merged
isakstenstrom merged 2 commits into
buildbarn:mainfrom
meroton:ci-integration
May 12, 2026
Merged

Ci integration#236
isakstenstrom merged 2 commits into
buildbarn:mainfrom
meroton:ci-integration

Conversation

@isakstenstrom

@isakstenstrom isakstenstrom commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

For some time, bb-portal has had hard-coded integrations against GitHub and GitLab, where invocations from the same workflow are grouped together into builds which have additional visualizations. This has worked well, but only when using any of those systems.

This PR makes the integration with CI systems configurable from the jsonnet file, allowing for integration with any CI system.

How to configure

A new configuration field has been added called invocationMetadataExtractor that accepts a Jmespath expression. Its purpose is to extract data from the environment variables Bazel is executed with. The result of the extractor is expected to be a JSON object with the following fields:

  • username: The username to be associated with the invocation.
  • hostname: The hostname for the computer that ran the invocation.
  • sourceControls: An array of objects representing a repository used by the invocation. The entity SourceControl now only contains a repo, ref and commit sha, as well as urls for each of them.
  • invocationTags: JSON object with key-values to be associated with the invocation.
  • buildTags: JSON object with key-values to be associated with the build.

Invocations are grouped togehter as builds based on the buildTags. A new config field has been added called buildKey, and invocations that have the same combination of instanceName and buildTags[buildKey] are grouped in the same build.

The tags are visualized on each build and invocation. Additionally, the build and build details tables can be configured with extra columns where specified tags are shown and can be filtered for.

Here is an example invocationMetadataExtractor for GitHub Actions:

{
  "username": env.USER
  "hostname": env.HOSTNAME
  "sourceControls": [
    {
      "repo": env.GITHUB_REPOSITORY
      "repoUrl": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY) && join('/', [env.GITHUB_SERVER_URL , env.GITHUB_REPOSITORY]) || `null`
      "ref": env.GITHUB_REF
      "refUrl": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_REF) && join('/', [env.GITHUB_SERVER_URL, env.GITHUB_REPOSITORY, 'tree', env.GITHUB_REF]) || `null`
      "commit": env.GITHUB_SHA
      "commitUrl": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_SHA) && join('/', [env.GITHUB_SERVER_URL, env.GITHUB_REPOSITORY, 'commit', env.GITHUB_SHA]) || `null`
    }
  ]
  "invocationTags": {
    "workflow": env.GITHUB_WORKFLOW
    "workflow_url": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_RUN_ID) && join('/', [env.GITHUB_SERVER_URL , env.GITHUB_REPOSITORY, 'actions', 'runs', env.GITHUB_RUN_ID]) || `null`
    "job": env.GITHUB_JOB
    "action": env.GITHUB_ACTION
  }
  "buildTags": {
    "repo": env.GITHUB_REPOSITORY
    "repo_url": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY) && join('/', [env.GITHUB_SERVER_URL , env.GITHUB_REPOSITORY]) || `null`
    "workflow": env.GITHUB_WORKFLOW
    "workflow_url": (env.GITHUB_SERVER_URL && env.GITHUB_REPOSITORY && env.GITHUB_RUN_ID) && join('/', [env.GITHUB_SERVER_URL , env.GITHUB_REPOSITORY, 'actions', 'runs', env.GITHUB_RUN_ID]) || `null`
  }
}

Relevant discussion: #211

@isakstenstrom
isakstenstrom marked this pull request as ready for review April 29, 2026 14:19
@isakstenstrom
isakstenstrom marked this pull request as draft May 4, 2026 12:14
The email field wasn't shown, and now that we have authenticated users,
this field isn't as useful. Also renames `user_ldap` -> `username`.
The Source Control has been reworked to make it possible to integrate
bb-portal with more CI and source control systems. The
`invocationMetadataExtractor` configuration controls what data is
stored. The extractor can do the following:

- Set the username associated with the invocation.
- Set the hostname associated with the invocation.
- Add `SourceControl`s to a invocation. A `SourceControl` consists of a
  `repo`, `commit` and a `ref`, as well as their urls.
- Set tags (key-value pairs) associated with a invocation. Each key is
  unique per invocation.
- Set tags (key-value pairs) associated with a build. Each combination
  of key and value is unique per build.

Invocations are grouped togehter as builds based on the buildTags. A new
config field has been added called `buildKey`, and invocations that have
the same combination of `instanceName` and `buildTags[buildKey]` are
grouped in the same build.

This replaces the old hardcoded way of integrating with Github and
Gitlab. Example configurations for Github + Github Actions, Gitlab +
Gitlab CI, and Github + SemaphoreCI are provided.
@isakstenstrom
isakstenstrom marked this pull request as ready for review May 11, 2026 13:26
@isakstenstrom
isakstenstrom merged commit 3de7d65 into buildbarn:main May 12, 2026
5 checks passed
@isakstenstrom
isakstenstrom deleted the ci-integration branch May 12, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants