Exemplo n.º 1
0
def jenkins_build(cs_id):
    logger.info("Requested URL /changeset/%d/build [POST]", cs_id)
    changeset = Changeset.query.filter(Changeset.id == cs_id).first()
    if changeset is None:
        flash("Changeset {0} doesn't exist".format(cs_id), "error")
        logger.error("Changeset %d doesn't exist", cs_id)
        return redirect(url_for('index'))
    if changeset.review.target in app.config["BRANCH_MAPPING"]:
        job_name = app.config["BRANCH_MAPPING"][changeset.review.target]
    else:
        job_name = changeset.review.target + "-ci"
    build_info = jenkins.run_job(job_name, changeset.sha1)
    if build_info is None:
        flash("Scheduling Jenkins build failed", "error")
        return redirect(url_for("changeset_info", cs_id=cs_id))
        
    if build_info == "DISABLED":
        flash("Project is disabled in Jenkins. Try again when it is enabled.", "notice")
        return redirect(url_for("changeset_info", cs_id=cs_id))

    build = Build(changeset_id=changeset.id, status=build_info["status"],
                  job_name=job_name, build_url=build_info["build_url"])
    build.request_id = build_info["request_id"]
    build.scheduled = build_info["scheduled"]
    if "build_number" in build_info:
        build.build_number = build_info["build_number"]
    db.session.add(build)
    db.session.commit()
    logger.info("Jenkins build for changeset id " + str(changeset.id) +
                " has been added to queue. Changeset: " + str(changeset) +
                " , build: " + str(build))
    flash("Jenkins build has been added to the queue", "notice")
    return redirect(url_for('changeset_info', cs_id=cs_id))
Exemplo n.º 2
0
 def test_run_job_exceptions(self):
     with HTTMock(jenkins_next_build_number, jenkins_schedule_error):
         result = jenkins.run_job("iwd-8.5.000-ci", "100")
     self.assertIsNotNone(result)