예제 #1
0
def search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp):
    '''
    @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)
    '''
    """
    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.
    """
    J = Jenkins(jenkinsurl)
    j = J[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()
예제 #2
0
def search_artifacts(jenkinsurl, jobid, artifact_ids=None ):
    """
    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 )
    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("Artifacts %s missing from %s #%i" % ( ", ".join( missing_artifacts ), jobid, build_id ))
    #noinspection PyUnboundLocalVariable
    raise ArtifactsMissing( missing_artifacts )