Ruby tools a pipeline runs

Why so many tools are Ruby

A pipeline is a list of commands, and several of the commands it runs are Ruby programs. That is why a Ruby job on a CI runner is often not about Rails at all: the runner installs Ruby because one of the tools needs it.

The four below appear in real pipelines often enough to recognise:

The same list explains why a container image for a build job sometimes carries Ruby even when the project is not Ruby: the tool that builds the artifact is.

Ask RubyGems what is current

The gem command can query the index without installing anything. The --exact flag keeps the answer to one gem:

gem list --remote --exact fastlane

fastlane (2.241.2)

gem list --remote --exact jekyll

jekyll (4.4.1)

That is a useful first step when a pipeline pins a tool version: the number on the remote is what a new install would pick today, and the difference from the pin is the reason a build changed without a commit.

What each one does in a pipeline

Fastlane runs a lane, a named sequence of build and upload steps, and the pipeline calls it as one command. Jekyll builds the site into a folder that the deploy step copies. Chef runs at the end of a deploy to put the machine into the declared state. Vagrant is a developer tool; it rarely runs in a pipeline, but a pipeline that tests it needs a hypervisor.

Each tool is a gem, so each one arrives the same way as minitest or rake. The difference is what a failure means: a failed Jekyll build is a broken page, a failed Chef run is a half-configured server, and both are worth stopping the pipeline for.

What to watch for

Pin the version of a tool that runs in the pipeline. Fastlane in particular changes its output and its lanes often, and an unpinned tool turns a green release into a red one without a line of your code changing.

Install the tool in the job that needs it, not in the project bundle, unless the project really depends on it. A linter belongs in the Gemfile; a deployment tool usually does not.

Questions

A new set of questions in a new order every time. Choose one answer for each, then check.

  1. Why does a CI runner install Ruby for a project that is not written in Ruby?

    Answer

    Because a tool the pipeline runs, such as Jekyll or Fastlane, is a Ruby program

    The image carries the language of the tool that builds the artifact, not of the project that is being built.

  2. What does this program print? line = "fastlane (2.241.2)" p line[/\((\d[\d.]*)\)/, 1]

    Answer

    "2.241.2"

    The capture group reads the version inside the parentheses, which is how a script compares a pin with the remote answer.

  3. What does this program print? p Gem::Version.new("2.241.2").segments

    Answer

    [2, 241, 2]

    A version is a list of numbers, which is why 2.241 is newer than 2.9.

  4. What does this program print? versions = ["4.4.1", "4.10.0"] p versions.max_by { |v| Gem::Version.new(v) }

    Answer

    "4.10.0"

    A string comparison would pick 4.4.1, and the version objects put 4.10.0 first where it belongs.

  5. Why pin the version of a tool that runs in the pipeline?

    Answer

    An unpinned tool can change its output or its lanes and turn a green release red without your code changing

    The pin turns a silent tool upgrade into an intentional commit with a diff and a log.

  6. What does this program print? p File.extname("Vagrantfile")

    Answer

    ""

    A Vagrantfile is Ruby code with no extension, which is why a syntax check needs the interpreter rather than a suffix rule.

  7. What does gem list --remote --exact fastlane tell you?

    Answer

    The newest release on RubyGems, without installing it

    The remote index answers what a fresh install would pick today, which is the number to compare with the pin.

  8. What does this program print? p Gem::Version.new("4.10.0") > Gem::Version.new("4.4.1")

    Answer

    true

    Ten is greater than four in the minor part, and only the version object compares it that way.

  9. Where does a deployment tool usually belong?

    Answer

    In the job that needs it, not in the project bundle, unless the project really depends on it

    A linter belongs in the Gemfile because the project uses it; a deployment tool is the pipeline's business.

  10. What does this program print? p "jekyll (4.4.1)".split(" ").first

    Answer

    "jekyll"

    The name is the first word of the line, and the version is the part in parentheses.

Article author: Arthur Isaev