Created
January 7, 2020 18:14
-
-
Save zodman/0a28a0ac43e5966a42caa029e0289b22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import argparse | |
import os | |
import time | |
import pprint | |
import sys | |
base_token = os.environ.get("bamboo_BAMBOO_TOKEN") | |
TOKEN = os.environ.get("BAMBOO_TOKEN", base_token) | |
headers = { "Authorization": f"Bearer {TOKEN}" } | |
URL =" https://bamboo.coke.com/rest/api/latest" | |
def main(queue_key): | |
assert TOKEN, "Missing Bamboo Token" | |
url = f"{URL}/queue/{queue_key}.json" | |
data = { | |
'stage':'', | |
'executeAllStages':"", | |
} | |
resp = requests.post(url, data=data, headers=headers) | |
resp.raise_for_status() | |
build_number = resp.json().get("buildNumber") | |
while True: | |
url = f"{URL}/result/{queue_key}/{build_number}.json" | |
r = requests.get(url, headers=headers) | |
r.raise_for_status() | |
data = r.json() | |
cicle_state = data.get("lifeCycleState") | |
print(cicle_state) | |
build_state = data.get("state") | |
if "finished" in cicle_state.lower(): | |
pprint.pprint(data) | |
if "successful" in build_state.lower(): | |
print("success") | |
return | |
else: | |
sys.exit(build_state) | |
time.sleep(6) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Run bamboo plans with api') | |
parser.add_argument("queue_key", help=" example: CDSGLB-CDSDEPDCL") | |
args = parser.parse_args() | |
main(args.queue_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment