Here's the diagram of the flow on what this repo is about
- Slack app with socket mode enabled
- Go >=1.20
You have options regarding Slack app. You can create a new app dedicated for jenkins-bot-go and slack jenkins plugin. Or use existing app. Install it to your slack workspace.
Get the App Token in Settings -> Basic Information
section, scroll down and you will see App Token. Create a new and
add these scopes:
connections:write
authorization:read
Next, you need to obtain the Bot Token. Go to Features -> OAuth & Permissions
.
Go to Scopes section and add these OAuth Scope:
chat:write
im:history
Scroll up and copy the bot token.
- Clone the repository
- run this to download the dependencies
go mod download
- Copy
.env.example
and modify them according to your configuration- for
JENKINS_URL
, you need to put your jenkins URL. for example:http://jenkins.localhost
- for
JENKINS_USERNAME
, you can use the current username (admin
for example) you're logged in to your Jenkins. Make sure you have access to the necessary pipeline jobs that is about to be integrated with the - for
JENKINS_USER_API_TOKEN
, you can obtain it in your profile by clicking your name next toLogout
button then clickConfigure
. Go toAPI Token
section and create one for the jenkins bot go SLACK_BOT_TOKEN
will be your slack bot tokenSLACK_APP_TOKEN
will be your slack bot tokenSLACK_DEFAULT_CHANNEL
set default channel to send the approval toAPP_DEBUG
you can choose betweentrue
orfalse
APP_MODE
you can choose betweenaio
orstandlone
. See more in running the app
- for
If you don't set the APP_MODE
, the default value would be aio
. That means both HTTP API and Slack bot will run at the same command
go run .
If you choose run them separately, set the APP_MODE
to standalone
. Then you can run the slack bot with
go run . artisan slack:socket
Create a new pipeline and copy this to see if it's working fine
stage("Setup") {
node('master') {
def host = "http://slack-bot.dev:3000/"
def data = [
"build_number": env.BUILD_NUMBER,
"build_name": env.JOB_NAME,
"message": "approval for ${env.JOB_NAME}"
]
def json = JsonOutput.toJson(data)
sh "curl -X POST -H 'Content-Type: application/json' ${host}/approval/jenkins --data '${json}'"
}
input("Approval required before proceeding deployment")
}
You can also build the binary and put it in your server or even build it in container and deploy it in your cluster.
PR or Issue submission are very much welcome. I will do my best to engage and resolve the said items.
Issues will be reviewed and resolved at best effort. However, if you need further assistance, do not hesitate to contact me at my email
- Initial Release
- Expand to other communication channel
- Slack
- Telegram
- Mattermost
- ...
- Integrate to other CI/CD tools if possible
- Jenkins
- Gitlab
- Allow Jenkins to directly send API request to jenkins-bot-go that will send approval message to Slack
- Security Layer