Build result notification etc. can already be posted to Slack (plugin is set)
import os
build_number = os.environ.get('BUILD_NUMBER')
BUILD_NUMBER on the Jenkins side Environment variables are prepared, so use this https://wiki.jenkins.io/display/JA/Building+a+software+project
pip install slacker
post_log.py
from slacker import Slacker
import sys
import os
token = 'Your SLACK token'
channel = 'Please enter the channel name'
build_number = os.environ.get('BUILD_NUMBER')
file = f'~/builds/{build_number}/log'
slacker = Slacker(token)
slacker.files.upload(file_=file, channels=channel)
files.upload official documentation https://api.slack.com/methods/files.upload
It is also possible to add comments, so please add parameters there. Once you've confirmed that it's actually posted to Slack, it's OK!
Recommended Posts