Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Omitting deployment variables in a Python script

I am building s simple python script to check  a canary service is up and validate a bamboo build # .  I have all the script logic complete except for one condition.  The script will be used in multiple projects. Some require a canary credential ( auth ) while others do not.  I can get one or the other working but not account for both.  Is there anyway to ignore a deploy variable ( using a python script ) ?

canary_username = sys.argv[1]
canary_password = sys.argv[2]
canary_host = sys.argv[3]
bamboo_deploy_version = os.environ["bamboo_deploy_version"]
bamboo_build_number = os.environ["bamboo_buildNumber"]

s = requests.Session()
s.auth = () #ONLY works WITHOUT credentials
s.auth = (canary_username, canary_password) #DOES NOT WORK WITHOUT credentials

# TODO: ensure all canary services require authentication
if canary_username == "null":
s.auth = ()


1 answer

0 votes

Hi @Landon Cooper,

Thank you for sharing all those details, but I'm still not quite clear of what you are trying to achieve.

What do you mean by:

 Is there anyway to ignore a deploy variable ( using a python script ) ?

Are you trying to omit canary_username and canary_password ?

Have you added the variable canary_password in your deployment environment or in the global variables page? (the name of this variable should trigger the feature in Bamboo that hides its content from the logs)

Hi @Daniel Santos

thanks for taking a look at this ( I'll try to add more detail).  So the canary check is a rest call to an end point. In some projects I need:


Others there is NO credential for the canary call:



So in the python script I would like to simply use a condition to define the s.auth for either case:


if canary_username != "null":
s.auth = (canary_username, canary_password)  # s.auth will default to () if not defined) 


The problem is that there is error when attempting to have the python script modify or replace, or omit the sys_argv[1] ( bamboo variable).  I've tried casting the variable as a specific type, putting it in a function, creating a second "buffer" var as a replacement, etc.   I would like the script to use the variable when a condition is true and  omit it when not true. 

I don't know how you plan to call your script for each plan. If you intend to call it differently depending on what variables you have available, one of the possible approaches is checking the number of arguments.

The following inline script will show you how you could check the number or arguments to decide which authentication to use:

import os
import sys

if len(sys.argv)==2:
canary_host =sys.argv[1]
# Just a random request with NO authentication
os.system("curl -X GET \'http://"+canary_host+":8085/bamboo/rest/api/latest/server\'")

elif len(sys.argv)==4:
canary_username = sys.argv[1]
canary_password = sys.argv[2]
canary_host = sys.argv[3]
# Just a random request using authentication
os.system("curl -u "+canary_username+":"+canary_password+" -X GET \'http://"+canary_host+":8085/bamboo/rest/api/latest/search/users?searchTerm=a\'")

print "len(sys.argv)={}", len(sys.argv)
print "Invalid arguments ERROR"

calling the script with NO authentication: $bamboo_canary_host

 calling the script with authentication: $bamboo_canary_username $bamboo_canary_password $canary_canary_host

you could even call the script with empty variables and it would call the authentication method without user and password: $bamboo_empty_var $bamboo_empty_var $bamboo_canary_host


 Please let me know if this make sense to you.

Like Landon Cooper likes this

@Daniel Santos   I thought about a form of this but was not sure how to go about it. I will try it and let you know.  Thanks for your thoughts!

This is a really ugly example just used as a test to try understanding what problems you were facing. I shared that small script just to give you some ideas. The real solution will depend on your company process, if you will declare or not the variables for all plans and how that script will be called.

Like Landon Cooper likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Bamboo Data Center on Kubernetes

Hi, If you are running self-managed environments and looking to adopt modern infrastructure, Bamboo Data Center can now be deployed in a Kubernetes cluster. By leveraging Kubernetes, you can easily...

46 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you