Sign inSign up

mgrafl/gitlab-ci-shellspec

By mgrafl

•Updated about 2 years ago

Unit testing GitLab CI/CD job scripts via ShellSpec

Image
Developer tools
0

2.7K

mgrafl/gitlab-ci-shellspec repository overview

A collection of helper functions for unit testing script clauses of GitLab CI/CD configuration files (.gitlab-ci.yml) via ShellSpec⁠.

⁠Overview

Assume the following .gitlab-ci.yml pipeline configuration:

variables:
  USER: Michael

job-1:
  script:
    - echo "Hello, World!"
    - echo "Hello, $USER!"

A unit test can verify the output:

#shellcheck shell=bash

Describe '.gitlab-ci.yml'
  BeforeEach ci_spec::export_all_global_variables

  It 'says hello to the world and to me'
    When call ci_spec::eval_job  'job-1'
    The lines of output should equal 2
    The 1st line should equal 'Hello, World!'
    The 2nd line should equal 'Hello, Michael!'
  End
End

The topic is also discussed in the blog post on Docker-based ShellSpec Tests for GitLab CI/CD Job Scripts⁠.

⁠Usage

To execute unit tests locally via Docker, run:

docker run --rm -t -v ".:/src" mgrafl/gitlab-ci-shellspec
⁠GitLab .gitlab-ci.yml

In the GitLab CI/CD configuration file .gitlab-ci.yml, use the Docker image, but override the entrypoint (see GitLab documentation on overriding the entrypoint of an image⁠).

shellspec:
  image: 
    name: mgrafl/gitlab-ci-shellspec
    entrypoint: [""]
  stage: test
  script: 
    - gitlab-ci-shellspec
⁠Repository

mgrafl/gitlab-ci-shellspec⁠ on GitLab.

⁠License

This project is licensed under the MIT license⁠.

Tag summary

Content type

Image

Digest

sha256:b40edde9c…

Size

17.6 MB

Last updated

about 2 years ago

docker pull mgrafl/gitlab-ci-shellspec