Open nmarjanovic opened 6 years ago
There are some ways you could access hostname. When the build runs, the build container has docker mounted from the host, so this means if you run additional docker containers, you can mount volumes from the host. a command like this: docker run -v /etc/hostname:/etc/hostname bash cat /etc/hostname
will print the host name to the logs.
You could take it one step further add add something like this to your env: global
section: HOST=$(docker run -v /etc/hostname:/etc/hostname bash cat /etc/hostname)
and then, throughout your build you can refer to $HOST as the hostname.
Another way to do this is to specify /etc/hostname:/etc/hostname
as a volume mount in your pre_ci_boot
section, and then anywhere in your build you can just cat /etc/hostname
, as the file will be mounted directly into your build container. See docs on how to mount volume in pre_ci_boot: http://docs.shippable.com/ci/build-image/#mounting-volumes
Does this option work for you? I think this would also be a nice feature for us to implement as a default globally available environment variable, so i'll open a ticket for that.
also I want to add that if you're using a runSh job, then you can actually create a task with the container: false
option to make your script run directly on the host, which should then get you the info you want with uname -n
Hi @trriplejay I will test and keep you posted. Thank you for all information provided.
I second this request and think it would make sense to have this as part of the Job node info step by default. The output of uname -a
within a Docker container is not really useful.
Hi,
For now i tested:
"Another way to do this is to specify /etc/hostname:/etc/hostname as a volume mount in your pre_ci_boot section, and then anywhere in your build you can just cat /etc/hostname, as the file will be mounted directly into your build container. See docs on how to mount volume in pre_ci_boot: http://docs.shippable.com/ci/build-image/#mounting-volumes"
pre_ci_boot: options: "-v /etc/hostname:/etc/hostname"
Then in ci i tested cat /etc/hostname, and it's working. I tested with hostname, but output are numbers.
can you provide a link to a build where you tried this? or your project id?
Hi @trriplejay
Project Id: 5770e1363be4f4faa56ae386 Build: 7833
From what I can tell, that project/build looks like it's behaving correctly. I can see in the output of your cat
command that the correct machine hostname is being printed. This action won't change the output of the job node info
section, it just allows you to determine the hostname from inside the build container.
I think i'm not sure what you mean by this statement:
I tested with hostname, but output are numbers.
Is there some other piece of this that didn't work as you expected?
Hostname is Linux command and usually you will get same output from cat /etc/hostname and hostname command. But mounted volume that is not the case from what I tested. That's all.
Notice that the sudo docker info
command in the Job node info build step shows the node hostname under Name
. Maybe that helps.
Hi,
As we have more then one build byon's, I want to get more info from "Job node info". Can that be done in shippable.yml and what variables can be used? I would like to grab node hostname, in your outputs we can see only "Linux 6ca342c3a754", from uname -a command.
Thanks