def promote_pipeline(conf, args):
    """Export a pipeline from a lower environment and import into higher environment."""
    src = conf.config['instances'][args.src_instance]
    src_url = api.build_pipeline_url(build_instance_url(src))
    src_auth = tuple([conf.creds['instances'][args.src_instance]['user'], conf.creds['instances'][args.src_instance]['pass']])
    verify_ssl = src.get('verify_ssl', True)
    export_json = api.export_pipeline(src_url, args.src_pipeline_id, src_auth, verify_ssl)

    # Import the pipeline to the destination
    dest = conf.config['instances'][args.dest_instance]
    dest_url = api.build_pipeline_url(build_instance_url(dest))
    dest_auth = tuple([conf.creds['instances'][args.dest_instance]['user'], conf.creds['instances'][args.dest_instance]['pass']])
    dest_pipeline_id = args.dest_pipeline_id
    if dest_pipeline_id and api.pipeline_status(dest_url, dest_pipeline_id, dest_auth, verify_ssl)['status'] != api.STATUS_STOPPED:
        api.stop_pipeline(dest_url, dest_pipeline_id, dest_auth, verify_ssl)
    else:
        # No destination pipeline id was provided, must be a new pipeline.
        create_json = api.create_pipeline(dest_url, dest_auth, export_json, verify_ssl)
        dest_pipeline_id = create_json['info']['pipelineId']

    result = api.import_pipeline(dest_url, dest_pipeline_id, dest_auth, export_json, verify_ssl, overwrite=True)

    # Start the imported pipeline
    if args.start_dest:
        api.start_pipeline(dest_url, dest_pipeline_id, dest_auth, verify_ssl)

    return result
Export a pipeline from a lower environment and import into higher environment.