Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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:

        http://USER:PASSWORD@SERVER:8181/canary/build/endpoint

Others there is NO credential for the canary call:

         http://SERVER:8181/canary/build/endpoint

 

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

i.e. 

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:

#!/usr/bin/python
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\'")

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

calling the script with NO authentication:

authentication.py $bamboo_canary_host

 calling the script with authentication:

authentication.py $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:

authentication.py $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
TAGS
Community showcase
Published in Bamboo

Bamboo 101 Video

G’day Community! As we gear up to introduce Bamboo Data Center to the world, we wanted to make sure that we shared a bit more about Bamboo, the product. Our team has put together an overview video ...

215 views 4 6
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