@making's memo

All Categories All Tags Premium (Beta)


ConcourseからLine Notify

Edit History

Concourseからの通知でLine Notify(API)を使うためにResourceを作ってみようと思ったけれど、
汎用的なHTTP API Resourceで簡単にできたので作るまでもなかった。

次のようなpipeline.ymlを作る

resource_types:
- name: http-api
  type: docker-image
  source:
    repository: aequitas/http-api-resource
resources:
- name: line-notify
  type: http-api
  source:
    uri: https://notify-api.line.me/api/notify
    method: POST
    headers:
      Authorization: "Bearer {access_token}"
    form_data:
      message: "{message}"
    access_token: {{line-notify-access-token}}
jobs:
- name: hello
  plan:
  - task: say-hello
    config:
      platform: linux
      image_resource:
        type: docker-image
        source:
          repository: alpine
      run:
        path: sh
        args:
        - -c
        - |
          echo "Hello"
    on_success:
      put: line-notify
      params:
        message: Hello from Concourse!!

次のcredentials.ymlにLine Notifyのアクセストークンを設定

line-notify-access-token: xxxxxxxxxxx

fly -t your-target set-pipeline -p hello-line -c pipeline.yml -l credentials.yml
fly -t your-target unpause-pipeline -p hello-line

実行

$ fly -t your-target trigger-job -j hello-line/say-hello --watch
started hello-line/say-hello #1

using version of resource found in cache
initializing
running sh -c echo "Hello"

Hello
Starting new HTTPS connection (1): notify-api.line.me
http response code: 200
http response text: {"status":200,"message":"ok"}
using version of resource found in cache
succeeded

できた。簡単。

気が向いたらLine Notify Resourceを作ろう。

このエントリーをはてなブックマークに追加