Function
def create_baseline_specific_folder(host_url, username, password, project_key,
folder_id, baseline_name, baseline_description):
"""
This method is used to create a new baseline on a given folder
Template parameters:
[project_key] the project key
[folder_id] the ID of the folder to create the baseline on
Query parameters:
[baseline_name] the name of the new baseline
[baseline_description] description of the new baseline
"""
# The REST API path to create a new baseline on a given folder
path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + \
project_key + '/baseline/' + folder_id + '?'
# The field-value pair/s that will be added to the query string
baseline_name_field_value = 'name=' + baseline_name
baseline_description_field_value = '&description=' + baseline_description
# The query string to be added to the URI
query_string = baseline_name_field_value + baseline_description_field_value
# Send a POST request to create a new baseline on the project's root folder
# Return the result of the POST request
try:
return requests.post(host_url + path_uri + query_string, auth=HTTPBasicAuth(username, password))
except requests.exceptions.RequestException as e:
print e
Main
# ['SC'] project key parameter where the baseline will be created
# ['242'] folder id parameter of the folder to be baseline
# ['GUI Requirement Release 1.0'] name parameter for the baseline to be created
# ['Baseline for GUI Requirement 1.0'] description parameter for the baseline to be created
# Store the result of the POST request to [response]
response = create_baseline_specific_folder(HOST_URL, USERNAME, PASSWORD, 'SC', '242',
'GUI Requirement Release 1.0', 'Baseline for GUI Requirement 1.0')
# Check response if baseline is created
if response.status_code == 200:
# Get the value of the JSON response and print in a readable JSON format
# json dumps formats the JSON string in readable format
json_object = json.loads(response.text)
print json.dumps(json_object, indent=4)
else:
print 'Error code: ', response.status_code
print response.text
Refer to Constant variable for information of the following constant variable: [HOST_URL, USERNAME, PASSWORD]
Output
{
"description": "Baseline for GUI Requirement 1.0",
"prjKey": "SC",
"created": 1506679832677,
"userId": "myUsername",
"id": 8,
"name": "GUI Requirement Release 1.0"
}