Skip to content

Jenkins Shared Library to retrieve build number from remote service

License

Notifications You must be signed in to change notification settings

liejuntao001/jenkins-buildnumber-lib

Repository files navigation

Jenkins Shared Library to get build number from service

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


Usage

Recommended Method 1 - Import into Jenkins

Import the library following the instruction import

Use it in pipeline

@Library("buildnumber") _

Method 2 - Load dynamically

@Library("github.com/liejuntao001/jenkins-buildnumber-lib") _

However due to Jenkins security control, multiple methods need get approved.

approved methods

Demo

Add Credentials

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.

demo1


demo1

Build and test

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 .

demojob

About

Jenkins Shared Library to retrieve build number from remote service

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages