Fully implement pipeline-notify in Ruby
This is an implementation issue for the pipeline-notify
portion of #523.
Feature completion
Configuration
Environment variables should be matched exactly in order to be interchangeable:
-
Gets the user from DEPLOY_USER
,GITLAB_USER_NAME
, orUSER
-
Gets the project name from CI_PROJECT_NAME
-
Gets a Slack API token from SLACK_DEPLOYER_TOKEN
-
Gets a GitLab version argument from DEPLOY_VERSION
-
Gets an ops.gitlab.net API token from OPS_PIPELINE_API_TOKEN
-
Gets a Grafana API key from GRAFANA_API_KEY
CLI
bin/pipeline-notify
-- the Python interface should be matched exactly in order to be interchangeable:
-
Supports mutually-exclusive --start
,--finish-success
, and--finish-failure
flags -
Requires an env_stage
positional argument, one ofgprd
,gprd-cny
,gstg
,pre
,dr
,release
-
Gets a Pipeline status from the ops.gitlab.net API
Implementation
The implementation does two distinct things:
- Annotate Grafana with start and end times for a deploy
- Send a Slack message
Annotate Grafana
-
Does nothing if CHECKMODE
is present -
Gets Grafana URL from GRAFANA_URL
-
Posts a JSON payload to the above URL, retrying for failures: -
time
- The start timestamp, including milliseconds -
timeEnd
- (For a finished deploy) The current time, including milliseconds, -
isRegion
- (For a finished deploy) -
text
- Some text describing the event -
tags
- Tags related to the event-
deploy
-
The username -
The environment -
The version
-
-
Send a Slack message
Where the Slack message is sent is determined via YAML configuration, and the existing format should be matched in order to be interchangeable.
-
Does nothing if NO_NOTIFY
is present -
Uses different channel configuration depending on CHECKMODE
-
Sends a formatted Slack message to any number of configured channels
Edited by Robert Speicher