Can Bamboo give a free port number to use in a build variable?

Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 16, 2014

I just want to ask Bamboo for a port number that is free of use (on the box the agent is running) that I can pass to my build. It seems that having that port available in a variable would be useful.

2 answers

0 votes
John Bowker February 26, 2014

If you use a scripting language like Python for building you get bind on port 0 on the remote agent. Binding on that port allows the os to tell which port is available for use.

def GetFreePort():
	"""Returns an available port"""
	sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sock.bind((socket.gethostbyname(socket.gethostname()), 0))
	return sock.getsockname()[1]

Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 26, 2014

Yep I've done similar things in Java in the past as well. What I'm looking for though is a way for Bamboo to do that and make that available to my build in a variable. This way I can integrate various tools in my build easily.

0 votes
Jason Monsorno
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2014

You could use netstat to show you what is in use. The port range you want to utilize is upto to you and there are some standards depending on what you're trying to use it for.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events