DATA CENTER AND SERVER | CLOUD

Get/Create Baselines

Contents


Get all existing baselines


The following script will get all existing baselines

 Click here to expand...
Function
def get_all_baselines(host_url, username, password):
    """
    This method is used to get all baselines
    """

    # The REST API path to search for tree elements
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/baselines'

    # Send a GET request to get all baselines
    # Return the result of the GET request
    try:
		return requests.get(host_url + path_uri, auth=HTTPBasicAuth(username, password))
	except requests.exceptions.RequestException as e:
    	print e
Main
# Store the result of the POST request to [response]
response = get_all_baselines(HOST_URL, USERNAME, PASSWORD)

# Check response if all baselines are returned
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 release 4.2", 
        "prjKey": "SC", 
        "created": 1506483953577, 
        "userId": "myUsername", 
        "id": 4, 
        "name": "Sand Castle Release 4.2"
    }, 
    {
        "description": "Baseline for release 5.1", 
        "prjKey": "SC", 
        "created": 1506483626814, 
        "userId": "myUsername", 
        "id": 3, 
        "name": "Sand Castle Release 5.1"
    }
]


Get all baselines for a given project


The following script will get all baselines for a given project. In this example, we will get all the baselines for the project Sand Castle 'SC'.

 Click here to expand...
Function
def get_baseline_by_project(host_url, username, password, project_key):
    """
    This method is used to get all baselines for a given project
    Template parameters:
    [project_key] the project key
    """

    # The REST API path to get all baselines for a given project
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/baselines/project/' + project_key

    # Send a GET request to get all baselines for a given project
    # Return the result of the GET request
    try:
		return requests.get(host_url + path_uri, auth=HTTPBasicAuth(username, password))
	except requests.exceptions.RequestException as e:
    	print e
Main
# ['SC'] project key parameter for the project where the baselines will be retrieved
# Store the result of the POST request to [response]
response = get_baseline_by_project(HOST_URL, USERNAME, PASSWORD, 'SC')

# Check response if all baselines of a project are returned
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 release 4.2", 
        "prjKey": "SC", 
        "created": 1506483953577, 
        "userId": "myUsername", 
        "id": 4, 
        "name": "Sand Castle Release 4.2"
    }, 
    {
        "description": "Baseline for release 5.1", 
        "prjKey": "SC", 
        "created": 1506483626814, 
        "userId": "myUsername", 
        "id": 3, 
        "name": "Sand Castle Release 5.1"
    }
]


Create baseline on the projects root folder


The following script will create a new baseline on the project root folder.

In this example, a new baseline will be created for the Sand Castle Release 4.2. The JSON response for the successful baseline creation will be printed.

 Click here to expand...
Function
def create_baseline_root_folder(host_url, username, password, project_key, baseline_name, baseline_description):
    """
    This method is used to create a new baseline on the project's root folder
    Template parameters:
    [project_key] the project key
    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 the project's root folder
    path_uri = '/rest/com.easesolutions.jira.plugins.requirements/1.0/tree/' + project_key + '/baseline?'

    # 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
# ['Sand Castle Release 4.2'] name parameter for the baseline to be created
# ['Baseline for release 4.2'] description parameter for the baseline to be created
# Store the result of the POST request to [response]
response = create_baseline_root_folder(HOST_URL, USERNAME, PASSWORD, 'SC',
                                       'Sand Castle Release 4.2', 'Baseline for release 4.2')

# 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 release 4.2", 
    "prjKey": "SC", 
    "created": 1506678665804, 
    "userId": "myUsername", 
    "id": 7, 
    "name": "Sand Castle Release 4.2"
}


Create a new baseline on a given folder


The following script will create a new baseline on a given folder. Returns the new baseline in case of success

In this example, a new baseline will be created for the GUI Requirement Folder for its 1.0 release milestone. The JSON response for the successful baseline creation will be printed.

 Click here to expand...
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"
}