Running pipelines from ChatOps Commands

This tutorial describes how to trigger pipelines from Github comments

Triggering Dispatch pipelines using ChatOps

Prerequisites

This tutorial assumes that you followed the steps on following pages:

Introduction

In this tutorial, a task test will be triggered by defining and using a ChatOps command /test

Configure ChatOps Trigger in Dispatchfile

To use the ChatOps feature, you must include a ChatOps action to trigger when a chat event occurs. As an example, we will examine a task written in Starlark from the pipeline configuration docs

#!mesosphere/dispatch-starlark:v0.5

load("github.com/mesosphere/dispatch-catalog/starlark/stable/pipeline@0.0.3", "gitResource")

gitResource("src-git")

task("test", inputs = ["src-git"], steps = [k8s.corev1.Container(
    name = "test",
    image = "golang:1.15.7-buster",
    command = [ "go", "test", "./..." ],
    workingDir = "/workspace/src-git",
    resources = k8s.corev1.ResourceRequirements(
        limits = {
            "cpu": k8s.resource_quantity("1000m"),
            "memory": k8s.resource_quantity("8Gi")
        }
    )
)])

action(tasks = ["test"], on = push(branches = ["master"]))
action(tasks = ["test"], on = pullRequest(chatops = ["test"]))

The following action:

action(tasks = ["test"], on = pullRequest(chatops = ["test"]))

runs the task test when there is a pull request when commented with /test. However, you can trigger the task with any word trailing a slash (/) for more details refer the configuration reference.

  1. Configure the tests to run in verbose mode, to enable viewing logs as the tests execute. Start by creating a new branch on the hello-world repo:
git checkout -b verbose-tests
  1. Make the change to the test task by changing the command to the following:
command = [ "go", "test", "-v", "./..." ],
  1. Add, commit, and push the changes to the Git repository.
git add Dispatchfile
git commit -m "Makes tests more verbose"
git push origin verbose-tests
  1. Open a Pull Request on GitHub. If you are unfamiliar, refer to the following documentation on GitHub

  2. Trigger a test by commenting /test on our Pull Request. To view the run, navigate to your Dispatch dashboard.