Vicky
Vicky

Reputation: 51

How to fetch Build information in jenkins

I've build a sample project in Jenkins by cloning from the Github repo. Can I get all the Jenkins and Git build details (such as the last commit ID, Origin details, Jenkins build number, Build URL, workspace location of Jenkins, Last commit author name) in a HTML page (It should be created after jenkins build) after triggering a build in Jenkins?

Upvotes: 1

Views: 947

Answers (3)

Tsahi Elkayam
Tsahi Elkayam

Reputation: 11

echo(env.getEnvironment().collect({environmentVariable ->  "${environmentVariable.key} = ${environmentVariable.value}"}).join("\n"))

Upvotes: 1

user_9090
user_9090

Reputation: 1974

You can get all the variables of the Jenkins pipeline by the below:-

script {
      // Prints all the variables
      sh "printenv"
}

After this you can store all the variables inside a file and publish that file using the HTML Publisher plugin to get the result in a HTML page. You can make changes in the below code:-

publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'fileDirectory', reportFiles: 'index.html', reportName: 'HTML Report', reportTitles: 'titleName'])

Upvotes: 1

akhlaq
akhlaq

Reputation: 19

Jenkins and Git provide global variables which can be directly accessed in jobs irrespective of pre build or post build actions. You can check global variable list with below url.

http://your-jenkins-url-here/env-vars.html

To access user defined variables, you can use below regex pattern:

${ENV,var="MY_VARIABLE_NAME"}

Upvotes: 1

Related Questions