The popular CI server Jenkins provides a rich API to access information about builds.
This API speaks JSON but the JSON it returns has a rather strange shape.
I needed to extract the Git revision built by a job, but Jenkins hides this information in a specific object in a “catch-all” actions
array which contains JSON objects of different shapes, many of which may or may not be present.
With Circe and some Shapeless magic I managed to decode this irregular JSON in a type-safe and fail-safe way (ignoring unknown JSON objects).
This actions
in the JSON model of a build looks as follows.
I converted the JSON to YAML to remove the syntactic boilerplate of JSON and make the snippet easier to read, and I also removed irrelevant parts: