DEV Community

Liejun Tao
Liejun Tao

Posted on

Get a build number from service

Recently I get a requirement to retrieve build number from external service for Jenkins Jobs.
Normally a Jenkins job uses BUILD_NUMBER in its display-name or as part of the version.
BUILD_NUMBER is just a sequential number, and it's bound to the specific job.
If several jobs are set up for the same project, either due to permission control, or sitting in multiple Jenkins instances, it's nice to retrieve build number from external service to keep consistent version.

So I come up with 2 small projects on GitHub:
Jenkins Shared Library to retrieve build number from remote service

A service to get an incremental number

The first one is a library used in Jenkins. Get a build number as simple as one line.

def build_number = buildnumber.get(server, uuid)

The second one is a simple service written by Go. It returns the incremental number each time called.
Deploy it on your own server, as a docker, or in a Kubernetes cluster.

Quick demo:

curl  -i  -H "Content-Type: application/json" -X POST https://buildnumber1.herokuapp.com/e9461f1c-ef78-4162-bcb7-e83da7287614

My first post. Thanks for reading.

Top comments (0)