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:
- main
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: Build with Maven
run: mvn install -f MyWebApp/pom.xml
- 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