Integrate your CI

This guide explains how to add an integration to other CI providers, so that users leveraging those providers can enjoy the new features.

Overview

At Netflix, we built CI integrations to enable features like the Builds view in Spinnaker, fetching artifact metadata and more. You can see the full list of CI features here .

Viewing CI details in Spinnaker

We recently added the option to see CI details in Spinnaker, in a new “Builds” tab. It looks like this:

Integrate your CI - 图1

This is a new tab that can be accessed from the main Spinnaker UI. The UI code (in deck) is calling the gate service to fetch information, and gate is just proxying the call to igor.

If you wish to use it, this is what you’ll need to do:

  1. Make sure you are using gate . Here’s the CiController the UI is calling (no need to do any actions here).
  2. Fork igor .
  3. Create a new service in igor which implements the <code>CiBuildService</code> interface, and contains two endpoints:
  • ci/builds which returns the GenericBuild object.
  • ci/builds/{buildId}/output which returns the build’s log by providing a build number, in a map format which looks like:
  1. {"log": "...."}
  • Example: your service implementation should be something like:
  1. public class SomeCiService implements CiBuildService[..]

These endpoints are called by the CiController .

Once both of these endpoints are implemented, it should be possible for the installations using that implementation to show CI information in Spinnaker! If you contribute a new implementation to the project, make sure to include documentation for operators explaining how to enable and configure it in their installation.

Managed Delivery artifacts

You can read about how the CI integration enriches the Managed Delivery experience with artifacts here .

Detecting a new published artifact

When a new artifact is published, keel gets notified by echo (for Debian packages) or by igor (for Docker images). Each artifact has a metadata section, which is populated by the corresponding artifact supplier implementation in keel. For example, for docker artifacts, the metadata field is populated by querying clouddriver, which stores information from the docker registries configured in the Spinnaker installation.

Here is an example of a Docker artifact event tracked by keel (this is a piece of a log statement):

  1. Received artifact published event: ArtifactPublishedEvent(artifacts=[PublishedArtifact(name=mce/agent, type=DOCKER,
  2. reference=dockerRegistry:v2:testregistry:mce/agent, version=h2012.2626f5f, customKind=false, location=testregistry, artifactAccount=null, provenance=null, uuid=null, metadata={date=1607111907158, registry=testregistry, fullname=mce/agent, tag=tag, commitId=2626f5f, buildNumber=2012, branch=tags/v1.2.0^0}

In order to get additional metadata for each tracked artifact (such as build and git details), we’ve created a convention that the buildNumber and commitId will be part of the artifact metadata object, regardless of the artifact type. In this example, we will query our CI provider to get metadata for build number 2012 and commit id 2626f5f.

Getting artifact metadata

Detailed metadata (like commit message, author, timestamp) is visible in the Environments view in the UI, by clicking on an artifact version.

In order to get the metadata information, you’ll have to plug in your CI provider. keel‘s buildService calls igor to fetch this information. It uses the endpoint <igorBaseURL>/ci/builds, which looks like:

  1. @GET("/ci/builds")
  2. @Headers("Accept: application/json")
  3. suspend fun getArtifactMetadata(
  4. @Query("commitId") commitId: String,
  5. @Query("buildNumber") buildNumber: String,
  6. @Query("projectKey") projectKey: String? = null,
  7. @Query("repoSlug") repoSlug: String? = null,
  8. @Query("completionStatus") completionStatus: String? = null
  9. ): List<Build>?

At Netflix, we pass as input the commitId and buildNumber. Those are mandatory to uniquely identify an artifact across repositories. The response contains a list of builds (we pick the first from the list), which look like:

  1. data class Build(
  2. val building: Boolean = false,
  3. val fullDisplayName: String? = null,
  4. val name: String? = null,
  5. val number: Int = 0,
  6. val duration: Long? = null,
  7. /** String representation of time in nanoseconds since Unix epoch */
  8. val timestamp: String? = null,
  9. val result: Result? = null,
  10. val url: String? = null, //url to get build details from the CI provider (like jenkins)
  11. val id: String? = null, //build uid
  12. val scm: List<GenericGitRevision>? = null,
  13. val properties: Map<String, Any?>? = null
  14. )

The Build object is a mirror of GenericBuild in igor.

Note: if you already implemented the /ci/builds endpoint as described above, jump to step 3 and you are done!

If you are interested in plugging your CI provider, you’ll need to do the following:

  1. Fork igor .
  2. Implement the ci/builds endpoint, and return a GenericBuild response (which is converted to Build object above).
  1. public class SomeCiService implements CiBuildService[...]
  1. Make sure the artifacts being sent to keel contains the buildNumber and commitId.

See code changes between deployments

The logic to generate a link to compare commits is done in keel: ArtifactVersionLinks .

Note: this supports only Stash/BitBucket at the moment. We’ll appreciate contributions for other SCMs!

Surface build information in the UI

A new section called “Pre-deployment” is now available in the UI. This section will surface pre-deployment steps like baking (for Debian packages only) or building. By clicking on “See details”, you’ll be taken to the CI-detailed view (see above), or a default job log which you can provide as a part of your implementation (in the url field in Build object, see above).

Last modified May 13, 2021: docs(migrate): add remaining Extending Spinnaker pages (3835a79)