Jenkins Integrations: Git Hosting, Slack and Email Notifications, REST API, CLI and Jira

CI CD Pipelines with Jenkins 40 min min read Updated: Nov 17, 2026 Intermediate
Jenkins Integrations: Git Hosting, Slack and Email Notifications, REST API, CLI and Jira
Intermediate Topic 2 of 2

Integration Map

text Git host (GitHub/GitLab/Bitbucket) ──webhook──► Jenkins ──status check──► pull request β”‚ β”œβ”€β”€β–Ί Slack / email / Teams (notify) β”œβ”€β”€β–Ί Jira (link build to issue) β”œβ”€β”€β–Ί SonarQube, Nexus (quality, artifacts) └──◄ REST API / CLI (scripts and bots call Jenkins)

GitHub

PiecePurpose
GitHub Branch Source pluginMultibranch and Organization Folder jobs: discovers branches and pull requests
GitHub App credentialBetter than a personal token: scoped, higher API limits, belongs to the organization
Webhook to https://jenkins.example.com/github-webhook/Starts builds instantly on push and pull request events
Commit status / Checks APIShows pass or fail on the pull request
  1. Create a GitHub App with permissions: Contents (read), Metadata (read), Pull requests (read), Commit statuses (read and write), Checks (read and write)
  2. Install it on your organization or repositories
  3. In Jenkins add the GitHub App credential (App ID and private key)
  4. Create an Organization Folder or a Multibranch job using that credential
  5. Add the webhook (the plugin can manage hooks) with a secret
groovy pipeline { agent any stages { stage('Test') { steps { sh './mvnw -B verify' } } } post { success { githubNotify context: 'ci/jenkins', status: 'SUCCESS', description: 'Build passed' } failure { githubNotify context: 'ci/jenkins', status: 'FAILURE', description: 'Build failed' } } }
Require the check: In GitHub branch protection, require the Jenkins status check before merging. Then broken code cannot reach main.

GitLab and Bitbucket

HostPluginNotes
GitLabGitLab plugin or GitLab Branch SourceWebhook URL https://jenkins.example.com/project/JOBNAME, secret token, reports status to merge requests
Bitbucket Cloud / ServerBitbucket Branch Source, Bitbucket Push and Pull RequestWebhook per repository, app passwords or access tokens
Gitea / Azure ReposTheir branch source pluginsSame pattern: webhook in, status out
groovy options { gitLabConnection('gitlab-main') } triggers { gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All') } post { success { updateGitlabCommitStatus name: 'jenkins', state: 'success' } failure { updateGitlabCommitStatus name: 'jenkins', state: 'failed' } }

Slack Notifications

groovy def notify(String status) { def color = [SUCCESS: 'good', UNSTABLE: 'warning', FAILURE: 'danger', ABORTED: '#999999'][status] ?: '#999999' def changes = currentBuild.changeSets.collectMany { it.items }.collect { "${it.author.fullName}: ${it.msg.take(60)}" }.take(5).join('\n') slackSend(channel: '#builds', color: color, message: "*${status}* ${env.JOB_NAME} #${env.BUILD_NUMBER} (${currentBuild.durationString.replace(' and counting', '')})\n<${env.BUILD_URL}|Open build>\n${changes}") } pipeline { agent any stages { stage('Build') { steps { sh 'make' } } } post { failure { script { notify('FAILURE') } } unstable { script { notify('UNSTABLE') } } fixed { script { notify('FIXED') } } // first success after failures } }
  • Send messages on failure, unstable and fixed only. Messages on every success become noise
  • Include: job, build number, who changed what, link to the log, duration
  • Use a separate channel for production deploy events
  • Store the Slack token in credentials (Slack plugin settings)

Email Notifications

groovy post { failure { emailext( subject: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}", body: '''${SCRIPT, template="groovy-html.template"}''', recipientProviders: [culprits(), requestor(), developers()], attachLog: true, compressLog: true) } }
  • Install Email Extension (emailext) and set SMTP in Manage Jenkins β†’ System
  • recipientProviders sends to people who changed the code (culprits), the starter (requestor) and committers (developers)
  • Use mail for a very simple message

Jenkins REST API

Almost every Jenkins page has an API: add /api/json to the URL. Use API tokens for authentication.

bash J=https://jenkins.example.com AUTH="-u ci-bot:$JENKINS_TOKEN" # Last build result of a job curl -sS $AUTH "$J/job/team-a/job/shop/lastBuild/api/json?tree=number,result,duration,timestamp" | jq # Build with parameters curl -sS -X POST $AUTH "$J/job/team-a/job/shop/buildWithParameters?BRANCH=main&DEPLOY=false" -D - -o /dev/null | grep -i location # Queue and executors curl -sS $AUTH "$J/queue/api/json?tree=items[task[name],why]" | jq curl -sS $AUTH "$J/computer/api/json?tree=computer[displayName,offline,numExecutors]" | jq # Console log curl -sS $AUTH "$J/job/team-a/job/shop/42/consoleText" | tail -50 # Stop a build curl -sS -X POST $AUTH "$J/job/team-a/job/shop/42/stop"
TipDetail
Use ?tree= to ask only for fields you needSmaller, faster responses
POST requests need CSRF crumb only with password authAPI tokens do not need a crumb
/job/FOLDER/job/NAME/Each folder level needs /job/
A queued build returns a Location headerFollow it to learn the build number

Jenkins CLI

bash # Download the client from your own Jenkins curl -sSO https://jenkins.example.com/jnlpJars/jenkins-cli.jar alias jcli='java -jar jenkins-cli.jar -s https://jenkins.example.com/ -auth ci-bot:$JENKINS_TOKEN -webSocket' jcli who-am-i jcli list-jobs team-a jcli build team-a/shop -p BRANCH=main -s -v # wait and show log jcli console team-a/shop 42 jcli install-plugin git -deploy jcli safe-restart
Admin power: CLI users with admin rights can change a lot. Create a limited service account for CLI scripts.

Trigger Builds Remotely

bash # Job option "Trigger builds remotely (e.g., from scripts)" with an authentication token curl -sS "https://jenkins.example.com/job/deploy/build?token=$JOB_TOKEN" # Generic Webhook Trigger plugin: map JSON fields into variables curl -sS -X POST -H "Content-Type: application/json" -d '{"ref":"refs/heads/main","service":"shop"}' \ "https://jenkins.example.com/generic-webhook-trigger/invoke?token=$HOOK_TOKEN"

Jira

  • Install the Jira plugin and connect it with a service account
  • Mention issue keys in commit messages (SHOP-123: fix cart total). Jenkins links builds to the issue
  • Use a pipeline step to comment or move an issue, for example jiraAddComment, or call the Jira REST API with curl and a credential
  • Use the issue key in the branch name (feature/SHOP-123-cart) so builds and pull requests link together

Practice Tasks

  1. Create a Multibranch job for a GitHub repository using a GitHub App credential
  2. Add a webhook, open a pull request and see the status check on it
  3. Send a Slack message on failure with the list of changes
  4. Read the last build result and the queue with curl and jq
  5. Trigger a parameterized build from a script with an API token

Conclusion

Jenkins connects to Git hosts through webhooks in and status checks out, to chat and email through notifications limited to useful events, and to scripts through the REST API and CLI with API tokens. Prefer GitHub App credentials, require the Jenkins check on protected branches, and keep tokens in credentials.

Quick Summary: GitHub App + webhook + status; GitLab/Bitbucket plugins; Slack/email on failure+fixed; REST API tree=; CLI; remote trigger/Generic Webhook; Jira keys.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators