Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new Microsoft Teams notifier #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
*.test

.vscode/
.idea/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ Cloud Build user and to have the
[gcloud CLI tool](https://cloud.google.com/sdk/gcloud/) installed and configured
for your Cloud Build project(s).

There are currently 3 supported notifier types:
There are currently 4 supported notifier types:

- [`smtp`](./smtp/README.md), which sends emails via an SMTP server.
- [`http`](./http/README.md), which sends (HTTP `POST`s) a JSON payload to
another HTTP endpoint.
- [`slack`](./slack/README.md), which uses a Slack webhook to post a message
in a Slack channel.
- [`teams`](./teams/README.md), which uses a Microsoft Teams webhook to post a message
in a Teams channel.

**See the official documentation on Google Cloud for how to configure each notifier:**

Expand Down
3 changes: 2 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ the repo) are:
* http
* slack
* smtp
* teams

Usage [in the cloud-build-notifiers repo root]:

Expand Down Expand Up @@ -57,7 +58,7 @@ main() {
# Check that the user is using a supported notifier type in the correct
# directory.
case "${NOTIFIER_TYPE}" in
http | smtp | slack | bigquery) ;;
http | smtp | slack | bigquery | teams) ;;
*) fail "${HELP}" ;;
esac

Expand Down
33 changes: 33 additions & 0 deletions teams/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang AS build-env
COPY . /go-src/
WORKDIR /go-src/teams
RUN go test /go-src/teams
RUN go build -o /go-app .

# From the Cloud Run docs:
# https://cloud.google.com/run/docs/tutorials/pubsub#looking_at_the_code
# Use the official Debian slim image for a lean production container.
# https://hub.docker.com/_/debian
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
FROM debian:buster-slim
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates && \
rm -rf /var/lib/apt/lists/*

FROM gcr.io/distroless/base
COPY --from=build-env /go-app /
ENTRYPOINT ["/go-app", "--alsologtostderr", "--v=0"]
20 changes: 20 additions & 0 deletions teams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Cloud Build Microsoft Teams Notifier

This notifier uses HTTP to `POST` JSON payload notifications in the
[legacy actionable message format](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference)
to a given
[incoming webhook connector](https://teams.microsoft.com/l/app/203a1e2c-26cc-47ca-83ae-be98f960b6b2?source=store-copy-link).

This notifier runs as a container via Google Cloud Run and responds to
events that Cloud Build publishes via its
[Pub/Sub topic](https://cloud.google.com/cloud-build/docs/send-build-notifications).

As this notifier is effectively an extension of the HTTP notifier, for detailed instructions on setting up this notifier,
see [Configuring HTTP notifications](https://cloud.google.com/cloud-build/docs/configuring-notifications/configure-http).

## Configuration Variables

This notifier expects the following fields in the `delivery` map to be set:

- `url`: The HTTP endpoint of the incoming webhook connector to which `POST` requests will be sent. No sort of
authentication is expected or used.
23 changes: 23 additions & 0 deletions teams/buildtest.cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
- name: gcr.io/cloud-builders/docker
args:
- build
- --file=./teams/Dockerfile
- '.'

tags:
- cloud-build-notifiers-teams
47 changes: 47 additions & 0 deletions teams/deploy.cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

steps:
# Build the binary and put it into the builder image.
- name: gcr.io/cloud-builders/docker
args:
- build
- --tag=${_REGISTRY}/teams:${TAG_NAME}
- --tag=${_REGISTRY}/teams:${_MAJOR_LATEST}
- --tag=${_REGISTRY}/teams:latest
- --file=./teams/Dockerfile
- '.'
# Run the smoketest to verify that everything built correctly.
- name: ${_REGISTRY}/teams:${TAG_NAME}
args:
- --smoketest
- --alsologtostderr

# Push the image with tags.
images:
- ${_REGISTRY}/teams:${TAG_NAME}
- ${_REGISTRY}/teams:${_MAJOR_LATEST}
- ${_REGISTRY}/teams:latest

options:
dynamic_substitutions: true

substitutions:
_REGISTRY: us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers
# Looks like: $NOTIF-$MAJOR-latest. Not meant for overriding.
_MAJOR_LATEST: "${TAG_NAME%%.*}-latest"

tags:
- cloud-build-notifiers-teams
- teams-${TAG_NAME}
22 changes: 22 additions & 0 deletions teams/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module github.com/GoogleCloudPlatform/cloud-build-notifiers/teams

go 1.14

replace github.com/GoogleCloudPlatform/cloud-build-notifiers/lib/notifiers => ../lib/notifiers

require (
cloud.google.com/go v0.62.0 // indirect
github.com/GoogleCloudPlatform/cloud-build-notifiers/lib/notifiers v0.0.0-20200731210753-3c7e9032cb03
github.com/antlr/antlr4 v0.0.0-20200801005519-2ba38605b949 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.4.2
github.com/google/cel-go v0.5.1 // indirect
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/sys v0.0.0-20200803150936-fd5f0c170ac3 // indirect
golang.org/x/tools v0.0.0-20200731060945-b5fad4ed8dd6 // indirect
google.golang.org/genproto v0.0.0-20200731012542-8145dea6a485
google.golang.org/grpc v1.31.0 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/yaml.v2 v2.3.0 // indirect
honnef.co/go/tools v0.0.1-2020.1.5 // indirect
)
Loading