Beispiel #1
0
def search_artifacts(jenkinsurl,
                     jobid,
                     artifact_ids=None,
                     username=None,
                     password=None,
                     ssl_verify=True):
    """
    Search the entire history of a jenkins job for a list of artifact names.
    If same_build is true then ensure that all artifacts come from the
    same build of the job
    """
    if len(artifact_ids) == 0 or artifact_ids is None:
        return []

    jenkinsci = Jenkins(jenkinsurl,
                        username=username,
                        password=password,
                        ssl_verify=ssl_verify)
    job = jenkinsci[jobid]
    build_ids = job.get_build_ids()
    for build_id in build_ids:
        build = job.get_build(build_id)
        artifacts = build.get_artifact_dict()
        if set(artifact_ids).issubset(set(artifacts.keys())):
            return dict((a, artifacts[a]) for a in artifact_ids)
        missing_artifacts = set(artifact_ids) - set(artifacts.keys())
        log.debug(msg="Artifacts %s missing from %s #%i" %
                  (", ".join(missing_artifacts), jobid, build_id))
    # noinspection PyUnboundLocalVariable
    raise ArtifactsMissing(missing_artifacts)
Beispiel #2
0
def search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp):
    '''
    Search the entire history of a hudson job for a build which has an artifact whose
    name matches a supplied regular expression. Return only that artifact.

    @param jenkinsurl: The base URL of the jenkins server
    @param jobid: The name of the job we are to search through
    @param artifactRegExp: A compiled regular expression object (not a re-string)
    '''
    job = Jenkins(jenkinsurl)
    j = job[jobid]

    build_ids = j.get_build_ids()

    for build_id in build_ids:
        build = j.get_build(build_id)

        artifacts = build.get_artifact_dict()

        for name, art in artifacts.iteritems():
            md_match = artifactRegExp.search(name)

            if md_match:
                return art

    raise ArtifactsMissing()
Beispiel #3
0
def search_artifact_by_regexp(jenkinsurl,
                              jobid,
                              artifactRegExp,
                              username=None,
                              password=None,
                              ssl_verify=True):
    '''
    Search the entire history of a hudson job for a build which has an
    artifact whose name matches a supplied regular expression.
    Return only that artifact.

    @param jenkinsurl: The base URL of the jenkins server
    @param jobid: The name of the job we are to search through
    @param artifactRegExp: A compiled regular expression object
        (not a re-string)
    @param username: Jenkins login user name, optional
    @param password: Jenkins login password, optional
    '''
    job = Jenkins(jenkinsurl,
                  username=username,
                  password=password,
                  ssl_verify=ssl_verify)
    j = job[jobid]

    build_ids = j.get_build_ids()

    for build_id in build_ids:
        build = j.get_build(build_id)

        artifacts = build.get_artifact_dict()

        try:
            it = artifacts.iteritems()
        except AttributeError:
            # Python3
            it = artifacts.items()

        for name, art in it:
            md_match = artifactRegExp.search(name)

            if md_match:
                return art

    raise ArtifactsMissing()