Integrating Slack with GitHub Actions for sending Notifications
Pre-requisites:
- Slack workspace is configured and channel created
- Make sure your Project is setup in GitHub
How to integrate Slack with GitHub Actions
We will be using slack GitHub Action Slack integration action for posting messages to Slack channel from GitHub Actions.
We will be following below steps:
1. Create a new App in https://api.slack.com/apps
2. Select workspace in the app
3.Select incoming webhooks
4. Activate incoming webhook
5. Add new webhook integration
6. Select channel, Allow
7. Copy the webhook url
Create App from scratch
Enter App name and pick a workspace
Click on incoming webhooksActivate incoming webhooks, click on Add new webhook to workspace
Add Slack Webhook URL as Secret in GitHub Actions
Go to your GitHub Repo --> Settings -->
Create GitHub Actions CICD workflow yaml:
Go to GitHub repo where your Java project is, create a new file:
.github/workflows/cicd.yml
name: cicd-workflow with slack integration
on:
push:
branches: [ "master" ]
jobs:
job1:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- uses: act10ns/slack@v2
with:
status: starting
channel: '#mar-2024-weekend-batch'
message: Starting Docker Build image...
if: always()
- uses: actions/checkout@v3
- name: Build Docker image
run: |
docker build -t my-docker-repo .
- uses: act10ns/slack@v2
with:
channel: '#mar-2024-weekday-batch'
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
if: always()
Watch Steps in YouTube channel:
No comments:
Post a Comment