def construct_message(jenkins_url, master_build_url, last_build, last_build_status,
                      build_cause, cause, changes):
    """Construct message to be send to Mattermost."""
    if last_build_status:
        message = "Master e2e job has finished with success status!\n"
    else:
        message = "Master e2e job has failed!\n"
    message += "Build number {n}\n".format(n=last_build)
    message += "Job log {u}{n}/console\n".format(u=master_build_url, n=last_build)
    message += "Upstream project: {u}\n".format(u=build_cause["upstreamProject"])
    message += "Upstream build: {n}\n".format(n=build_cause["upstreamBuild"])
    message += "Upstream log: {j}{u}{n}/console\n".format(j=jenkins_url,
                                                          u=build_cause["upstreamUrl"],
                                                          n=build_cause["upstreamBuild"])
    message += "Cause: {c}\n".format(c=cause)
    message += "Changes:\n{c}\n".format(c=changes)
    return message.strip()