Example #1
0
def create_build_configuration_and_repo(environment, bc_set, product_version_id, art_params,
                               scm_repo_url, scm_revision, artifact_name, project):
    bpm_task_id = 0

    #Create BPM build config using post /bpm/tasks/start-build-configuration-creation
    #Set these SCM fields: scmRepoURL and scmRevision
    #Fields scmExternalRepoURL and scmExternalRevision can be optionally filled too
    bpm_task_id = bpmbuildconfigurations.create_build_configuration_process(
                                             repository=scm_repo_url,
                                             revision=scm_revision,
                                             name=artifact_name,
                                             project=project,
                                             environment=environment,
                                             build_script=get_maven_options(art_params),
                                             product_version_id=product_version_id,
                                             dependency_ids = [],
                                             build_configuration_set_ids = [],
                                             generic_parameters=get_generic_parameters(art_params))

    if not bpmbuildconfigurations.wait_for_repo_creation(bpm_task_id):
        return None

    #Get BC - GET build-configurations?q='$NAME'
    #Not found-> BC creation failed and the task was garbage collected -> fail
    #Success -> add BC to BCSet and return BC
    build_config = get_build_configuration_by_name(artifact_name)
    if build_config == None:
        logging.error("Creation of Build Configuration failed. Unfortunately the details were garbage collected on PNC side.")
        return None

    logging.info("Build Configuration " + artifact_name + " is created.")
    return build_config
Example #2
0
def create_build_configuration_and_repo(environment, bc_set,
                                        product_version_id, art_params,
                                        scm_repo_url, scm_revision,
                                        artifact_name, project):
    bpm_task_id = 0

    #Create BPM build config using post /bpm/tasks/start-build-configuration-creation
    #Set these SCM fields: scmRepoURL and scmRevision
    #Fields scmExternalRepoURL and scmExternalRevision can be optionally filled too
    bpm_task_id = bpmbuildconfigurations.create_build_configuration_process(
        repository=scm_repo_url,
        revision=scm_revision,
        name=artifact_name,
        project=project,
        environment=environment,
        build_script=get_maven_options(art_params),
        product_version_id=product_version_id,
        dependency_ids=[],
        build_configuration_set_ids=[],
        generic_parameters=get_generic_parameters(art_params))

    #Using polling every 30s check this endpoint: get /bpm/tasks/{bpm_task_id}
    #until eventType is:
    # BCC_CONFIG_SET_ADDITION_ERROR BCC_CREATION_ERROR BCC_REPO_CLONE_ERROR BCC_REPO_CREATION_ERROR -> ERROR -> end with error
    # BCC_CREATION_SUCCESS  -> SUCCESS
    error_event_types = ("RC_REPO_CREATION_ERROR", "RC_REPO_CLONE_ERROR",
                         "RC_CREATION_ERROR")
    time.sleep(2)
    while True:
        bpm_task = bpmbuildconfigurations.get_bpm_task_by_id(bpm_task_id)

        if contains_event_type(bpm_task.content.events,
                               ("RC_CREATION_SUCCESS", )):
            break

        if contains_event_type(bpm_task.content.events, error_event_types):
            pprint("Creation of Build Configuration failed")
            pprint(bpm_task.content)
            return None

        pprint("Waiting until Build Configuration " + artifact_name +
               " is created.")
        time.sleep(10)

    #Get BC - GET build-configurations?q='$NAME'
    #Not found-> BC creation failed and the task was garbage collected -> fail
    #Success -> add BC to BCSet and return BC
    build_config = get_build_configuration_by_name(artifact_name)
    if build_config == None:
        pprint(
            "Creation of Build Configuration failed. Unfortunately the details were garbage collected on PNC side."
        )
        return None

    pprint("Build Configuration " + artifact_name + " is created.")
    return build_config