kalyan
kalyan

Reputation: 43

Concourse Slack alert

I have written a bash script it process some data and puts in one file. My intention is to give slack alert if there is content in that file if not it should not give the alert. Is there a way to do it? In Concourse

Upvotes: 1

Views: 814

Answers (1)

Josh Ghiloni
Josh Ghiloni

Reputation: 1300

You should take advantage of the Concourse community's open source resource types. There's a list here. There is a slack resource listed on that page, but I use the one here (not included in the list above because it has not been added by the authors) https://github.com/cloudfoundry-community/slack-notification-resource.

That will give you the ability to add a put step in your job plan to send a slack resource. As for the logic of your original ask, you can use try and on_success. Your task might look something like this:

- try:
    task: do-a-thing 
    config:
      platform: linux

      image_resource:
      type: registry-image
      source:
          repository: YOUR_TASK_IMAGE
          tag: latest

      inputs:
      - name: some-input    
      params:
        FILE: some-file

      run:
        path: /bin/sh
        args:
        - -ec
        - |
          [ ! -z `cat some-input/${FILE}` ]
    on_success:
      put: slack
      params:
        <your slack resource put params go here>

The on_success part will run if the code defined in the task's run section returns 0. The script listed there just checks to see if there are more than zero bytes in the file. Because the task is wrapped in a try step, regardless of whether or not the task succeeds (and hence, sends you a message), the step will succeed and move to the next step in the plan.

Upvotes: 1

Related Questions