This is a Jenkins Shared Library to retrieve build number from external service.
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.
Here is A service to get an incremental number
Import the library following the instruction
Use it in pipeline
@Library("buildnumber") _
@Library("github.com/liejuntao001/jenkins-buildnumber-lib") _
However due to Jenkins security control, multiple methods need get approved.
Add Credentials
Below values are for demo purpose ONLY
build_number_server = https://buildnumber1.herokuapp.com/
test_job_uuid = e9461f1c-ef78-4162-bcb7-e83da7287614
In this demo, 2 pipelines are running same Demo pipeline
pipeline test1 get build_number 4, and pipeline Demo1 get build_number 5.
The library is a gradle project.
.
├── build.gradle
├── src
│ └── com
├── test
│ ├── com
│ └── groovy
├── testjobs
│ └── buildnumber_Jenkinsfile.groovy
└── vars
└── buildnumber.groovy
Local build and test
./gradlew clean test
> Task :test
BuildNumberTest: testGet: SUCCESS
java.net.ConnectException: Connection refused
[:]
BuildNumberTest: testGetFailed: SUCCESS
SimpleHttpsTest: testGet: SUCCESS
SimpleHttpsTest: testPost1: SUCCESS
SimpleHttpsTest: testPost: SUCCESS
java.net.ConnectException: Connection refused
SimpleHttpsTest: testBadHost: SUCCESS
SimpleHttpsTest: testBadLink: SUCCESS
Tests: 7, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESSFUL in 7s
Run the demo in a real Jenkins Job .