For the complete documentation index, see llms.txt. This page is also available as Markdown.

Ruby

Use a CI pipeline to build and test a Ruby application.

You can build and test a Ruby application using a Linux platform on Harness Cloud or a self-managed Kubernetes cluster build infrastructure.

This guide assumes you've created a Harness CI pipeline.

Install dependencies

Run Bundler commands in a Run step to install dependencies in the build environment.

- step:
    type: Run
    identifier: dependencies
    name: Dependencies
    spec:
      shell: Sh
      command: |-
        bundle check || bundle install
- step:
    type: Run
    identifier: dependencies
    name: Dependencies
    spec:
      connectorRef: YOUR_IMAGE_REGISTRY_CONNECTOR
      image: ruby:latest
      command: |-
        bundle check || bundle install

Cache dependencies

You can cache your Ruby dependencies with Cache Intelligence. Add caching.enabled.true to your stage.spec and specify the cache paths (in paths and sharedPaths).

- stage:
    spec:
      caching:
        enabled: true
        key: cache-{{ checksum "Gemfile.lock" }}
        paths:
          - "vendor/bundle"
      sharedPaths:
        - vendor/bundle

You can use built-in steps to:

Here's an example of a pipeline with Save Cache to S3 and Restore Cache from S3 steps.

            steps:
              - step:
                  type: RestoreCacheS3
                  name: Restore Cache From S3
                  identifier: Restore_Cache_From_S3
                  spec:
                    connectorRef: AWS_connector
                    region: us-east-1
                    bucket: some_s3_bucket
                    key: cache-{{ checksum "Gemfile.lock" }}
                    archiveFormat: Tar
              - step:
                  type: Run
                  ...
              - step:
                  type: BuildAndPushDockerRegistry
                  ...
              - step:
                  type: SaveCacheS3
                  name: Save Cache to S3
                  identifier: Save_Cache_to_S3
                  spec:
                    connectorRef: AWS_connector
                    region: us-east-1
                    bucket: some_s3_bucket
                    key: cache-{{ checksum "Gemfile.lock" }}
                    sourcePaths:
                      - vendor/bundle
                    archiveFormat: Tar

Build and run tests

You can use Run and Test steps to run tests in Harness CI.

The following examples run tests in a Run step.

Visualize test results

If you want to view test results in Harness, your test reports must be in JUnit XML format.

If you use a Run step to run tests, your Run step must include the reports specification. The reports specification is not required for Test steps (Test Intelligence).

The following examples use the Minitest JUnit Formatter. For more information and an RSpec example, go to Format test reports - Ruby.

Run tests with Test Intelligence

Test Intelligence is available for Ruby unit tests.

Test splitting

Harness CI supports test splitting (parallelism) for both Run and Test steps.

Specify version

Ruby is pre-installed on Harness Cloud runners. For details about all available tools and versions, go to Platforms and image specifications.

If your application requires a specific Ruby version, add a Run step to install it.

Install one Ruby version
Use multiple Ruby versions
  1. Add a matrix looping strategy configuration to your stage.

  1. Reference the matrix variable in your steps.

Specify the desired Ruby Docker image tag in your steps. There is no need for a separate install step when using Docker.

Use a specific Ruby version
Use multiple Ruby versions
  1. Add a matrix looping strategy configuration to your stage.

  1. Reference the matrix variable in the image field of your steps.

Full pipeline examples

The following YAML examples describe pipelines that install dependencies, run tests, use caching, and build and push images to Docker Hub.

This pipeline uses Harness Cloud build infrastructure and Cache Intelligence.

If you copy this example, replace the placeholder values with appropriate values for your connector IDs, account/user names, and repo names. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.

This pipeline uses self-managed Kubernetes cluster build infrastructure and Save and Restore Cache from S3 steps.

If you copy this example, replace the placeholder values with appropriate values for your connector IDs, account/user names, repo names, and other settings. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.

Next steps

Now that you have created a pipeline that builds and tests a Ruby app, you could:

Last updated

Was this helpful?