Skip to content

Commit be8e60a

Browse files
authored
Divide examples into individual folders + another bamboo example (#448)
* Confluence: resolve #412 * Rest API: handling https requests custom way * Reorder examples, add simple .md * Add another bamboo example * Make rest_client unchanged again * fix formatting
1 parent 2bd3636 commit be8e60a

File tree

51 files changed

+69
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+69
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
import logging
3+
from os import environ
4+
5+
from atlassian import Bamboo
6+
7+
"""
8+
To set up variables, use:
9+
export BAMBOO_URL=https://your-url BAMBOO_PASSWORD=your_pass BAMBOO_USERNAME=your_username
10+
You also can use .env files, check the awesome python-dotenv module:
11+
https://github.com/theskumar/python-dotenv
12+
"""
13+
bamboo = Bamboo(
14+
url=environ.get("BAMBOO_URL"),
15+
username=environ.get("BAMBOO_USERNAME"),
16+
password=environ.get("BAMBOO_PASSWORD"),
17+
advanced_mode=True # In this app I use an advanced_mode flag to handle responses.
18+
)
19+
20+
21+
def execute_build(build_key, params):
22+
"""
23+
build_key: str
24+
params: dict
25+
"""
26+
started_build = bamboo.execute_build(build_key, **params)
27+
logging.info(f"Build execution status: {started_build.status_code}")
28+
if started_build.status_code == 200:
29+
logging.info(f"Build key: {started_build.json().get('buildResultKey')}")
30+
logging.info(started_build.json().get('link', {}).get("href"))
31+
else:
32+
logging.error(f"Execution failed!")
33+
logging.error(started_build.json().get("message"))
34+
35+
36+
if __name__ == '__main__':
37+
"""
38+
This part of code only executes if we run this module directly.
39+
You can still import the execute_build function and use it separately in the different module.
40+
"""
41+
# Setting the logging level. INFO|ERROR|DEBUG are the most common.
42+
logging.basicConfig(level=logging.INFO)
43+
# Initialize argparse module with some program name and additional information
44+
parser = argparse.ArgumentParser(
45+
prog="bamboo_trigger",
46+
usage="%(prog)s BUILD-KEY --arguments [KEY VALUE]",
47+
description="Simple execution of the bamboo plan with provided key-value arguments"
48+
)
49+
# Adding the build key as the first argument
50+
parser.add_argument("build", type=str, help="Build key")
51+
# Adding key=value parameters after the --arguments key
52+
parser.add_argument("--arguments", nargs="*")
53+
# Getting arguments
54+
args = parser.parse_args()
55+
# Make a dictionary from the command arguments
56+
build_arguments = {args.arguments[i]: args.arguments[i + 1] for i in range(0, len(args.arguments or []), 2)}
57+
# Pass build key and arguments to the function
58+
execute_build(args.build, build_arguments)
File renamed without changes.

0 commit comments

Comments
 (0)