Skip to content

Support for GitLab Chatops using Slash commands

Yorick Peterse requested to merge chatops into master

What does this MR do?

This MR adds support for GitLab Chatops by scheduling a CI pipeline for every chat command. This allows one to define commands directly in .gitlab-ci.yml. For example:

    - 'echo "Your input was: $CHAT_INPUT"'
    - 'fortune -s'
    - psql -h /home/yorickpeterse/Projects/gitlab/gdk-ee/postgresql -d gitlabhq_development -q -c "EXPLAIN (ANALYZE, BUFFERS) $CHAT_INPUT;"
    - exit 1

Using such a configuration file you can run commands by running /root-slash-command-here run explain select count(*) from users where root-slash-command-here is the root command (e.g. /gl-infra or /chatops-test).

Input to the commands is provided using the CHAT_INPUT environment variable. This variable is set to the text that comes after the command name (ignoring leading whitespace). In the above example that would be select count(*) from users.

Output is sent back in one of two ways:

  1. If it's small enough we just send it as-is (mentioning the user in the process).
  2. If the output is too large we send back a link to the build. Currently the limit is 3.5 KB as Slack enforces a limit of around 4 KB per message

Output produced also always contains links to the project, pipeline, and the build.

See commit 63b36051 for more details.




  • Make sure that the code has some better documentation here and there
  • Double check the changes to see if all relevant code has tests
  • Make sure guests can't schedule pipelines via chat (IIRC this should already be covered but double checking doesn't hurt)

Does this MR meet the acceptance criteria?

What are the relevant issue numbers?

Edited by Kamil Trzciński

Merge request reports