0

How can I access the Jenkins build number and job path from the called Java program into this program?

Background: during the Java program runs, I want to create a dynamic link with this program (pathtothecurrentbuild/log) to the log file of the current run as an information for the admins in case of trouble.

dur
  • 15,689
  • 25
  • 79
  • 125

3 Answers3

3

Already the jenkins job are predefined with set of some environment variables like BUILD_NUMBER,JOB_NAME etc. These list of variables with name and description will be available in the url - http:// Your Jenkin URL/env-vars.html (Ex:http://cptest-Jenkins/env-vars.html)

These list of environment variables can be easily accessed using below code.

System.out.println("Build Number:"+System.getenv("BUILD_NUMBER")); //BUILD_NUMBER - name of the environment variable

This will print the current build number. Same way you can access other variables also.

1

Not sure how your java program is called but they should be set and environment-variables in the job so you should be able to access them from java or send them as parameters to the java program.

https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project

MaTePe
  • 936
  • 1
  • 6
  • 11
  • I thought about again and "print" out the whole environment of a running job. I found some env vars, that helps and so I solved this one. –  Nov 30 '16 at 11:20
0

You can have following line in your application.properties. service.version=${BUILD_NUMBER}

and then from in your java code, you can use this service.version.