0

I'm using jenkins to build my projects and i can't get the hostname with java

According to this java doc I wrote the follow lines

            System.out.println(System.getenv("MACHINE"));
            System.out.println(System.getenv("HOSTNAME"));

These are environment variables. BUt the output on build is:

 null
 null

What I'm doing wrong?

Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55

2 Answers2

1

If you are using the Jenkins script console, you can try:

println InetAddress.getLocalHost()

There is some very good discussion on this topic here.

Community
  • 1
  • 1
Amit
  • 1,006
  • 1
  • 7
  • 13
0

I solve the problem using the Jenkins Enviromenment Script Plugin

Wiht this plugin I can just run a shell script code and save the values as var to use in the build.

host=$(hostname)
flavor=$(cat /etc/os-release |grep ^'NAME=' |cut -d'=' -f2)
Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55