/jenkins-telegram-chatops

Telegram bot for running Jenkins jobs

Primary LanguageJavaMIT LicenseMIT

Jenkins telegram chatops

Conventional Commits Quality Gate Status Reliability Rating Maintainability Rating Security Rating

Bugs Code Smells Vulnerabilities

Duplicated Lines (%) Lines of Code Technical Debt

Jenkins-telegram-chatops is a Telegram bot written using Spring Boot which handing able to show list of Jenkins jobs and run specific job.

Key features

  • listing Jenkins jobs using /jobs command
  • running specific Jenkins job
  • monitoring using Prometheus
  • holding secrets with HashiCorp Vault

Build

Build from source

You can build application using following command:

./gradlew clean build

Requirements:

JDK >= 11

Unit tests

You can run unit tests using following command:

./grdlew test

Mutation tests

You can run mutation tests using following command:

./grdlew pitest

You will be able to find pitest report in build/reports/pitest/ folder.

Running jenkins-telegram-chatops

After the build you will get fully executable jar archive

You can run application using following commands:

java -jar jenkins-telegram-chatops.jar

or

./jenkins-telegram-chatops.jar

Configuration

According to Spring Docs you can override default application properties by put custom application.properties file in one of the following locations:

  • a /config subdirectory of the current directory
  • the current directory

Custom properties

jenkins.url
URL to Jenkins instance
jenkins.username
Jenkins username for REST API
jenkins.token
Jenkins user`s password or token for REST API
jenkins.poolSize
Size of FixedThreadPool
telegram.bot.name
telegram bot name
telegram.bot.token
telegram bot token
telegram.bot.users
coma separated list of bot users telegram IDs
telegram.bot.proxyHost
http proxy host
telegram.bot.proxyPort
http proxy port
telegram.bot.connectionTimeout
timeout in milliseconds until a connection is established
telegram.bot.connectionRequestTimeout
timeout in milliseconds used when requesting a connection
telegram.bot.socketTimeout
the socket timeout in milliseconds, which is the timeout for waiting for data or, put differently, a maximum period inactivity between two consecutive data packets)

Retryable configuration for checking Jenkins jobs status

When Jenkins job run via REST API jenkins-telegram-chatops waits until it finished. There are three steps :

  • wait until job in Jenkins queue
  • wait until job not started yet
  • wait until job building

Each steps performs REST API calls in maxAttempts attempts with some delay.

jenkins.retry.inqueue.maxAttempts
count max calls for `wait until job in Jenkins queue`
jenkins.retry.inqueue.backoff.delay
delay in ms for `wait until job in Jenkins queue`
jenkins.retry.notstarted.maxAttempts
count max calls for `wait until job not started yet`
jenkins.retry.notstarted.backoff.delay
delay in ms for `wait until job not started yet`
jenkins.retry.building.maxAttempts
count max calls for `wait until job building`
jenkins.retry.building.backoff.delay
delay in ms for `wait until job building`

Running Jenkins jobs

sequence diagram

INTEGRATIONS

Monitoring using Prometheus

You can access prometheus metrics by url:

{host:port}/actuator/prometheus

Holding secrets with HashiCorp Vault

Integration with Vault was made using spring-cloud-vault.

By default jenkins-telegram-chatops integration with Vault disabled.

To enable integration with Vault pass following arguments to jenkins-telegram-chatops run command:

java -jar jenkins-telegram-chatops.jar --spring.cloud.vault.enabled=true --spring.cloud.vault.uri=<your vault uri> 
--spring.cloud.vault.token=<your vault token> --spring.cloud.vault.kv.application-name=<vault application name>

Contributing

Feel free to contribute. New feature proposals and bug fixes should be submitted as GitHub pull requests. Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request.

IMPORTANT!

Before contributing please read about Conventional Commits / Conventional Commits RU