Saffire
Saffire

Reputation: 29

How to fetch the jenkins build number in my @afterSuite method

Every time I run a jenkins job, I basically want to fetch that jenkins build number and create a backup folder in my project workspace which has @afterSuite method .So my backUp folder name and the executed jenkins build number should match. The purpose to create a backup folder is to move a couple of log and report files. I have seen a lot of answers for setting a customised jenkins build number from project code, that is not my ask. My ask is i want the currently executing jenkins build number

Upvotes: 1

Views: 228

Answers (1)

Sourav
Sourav

Reputation: 3402

You can get the current build number using ${env.BUILD_NUMBER}

Simple pipeline example:

pipeline {
agent any
stages {
    stage ('Greeting'){
        steps {
            echo "Hello, The build number is: ${env.BUILD_NUMBER}"
        }
    }
}
}

Output: enter image description here

All the jenkins environment variables can be accessible using ${env.BUILD_NUMBER} or ${env.BUILD_URL} etc etc

Upvotes: 0

Related Questions