use of org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo in project platformlayer by platformlayer.
the class JenkinsCasStore method findTag.
@Override
public Md5Hash findTag(String tag) throws OpsException {
URI uri = client.getBaseUrl();
// TODO: Match jenkins host??
String[] tokens = tag.split(":");
if (tokens.length != 3) {
return null;
}
String jobKey = tokens[0];
String promotionKey = tokens[1];
String fileName = tokens[2];
String treeFilter = "fingerprint[fileName,hash]";
BuildInfo buildInfo;
try {
buildInfo = client.findPromotedBuild(jobKey, promotionKey, treeFilter);
if (buildInfo == null) {
return null;
}
} catch (JenkinsException e) {
throw new OpsException("Error communicating with Jenkins", e);
}
FingerprintInfo found = null;
List<FingerprintInfo> fingerprints = buildInfo.getFingerprints();
for (FingerprintInfo fingerprint : fingerprints) {
if (fileName.equals(fingerprint.getFileName())) {
found = fingerprint;
}
}
if (found == null) {
for (FingerprintInfo fingerprint : fingerprints) {
String fingerprintFileName = fingerprint.getFileName();
if (fingerprintFileName.contains(":")) {
// Strip the maven prefix
fingerprintFileName = fingerprintFileName.substring(fingerprintFileName.indexOf(':') + 1);
}
if (fileName.equals(fingerprintFileName)) {
found = fingerprint;
}
}
}
if (found == null) {
log.warn("Could not find fingerprinted file with name: " + fileName + " in " + buildInfo);
return null;
}
String hash = found.getHash();
if (hash == null) {
throw new IllegalStateException();
}
// We return the hash in the hope that we've already copied the artifact!
return new Md5Hash(hash);
}
use of org.platformlayer.ops.cas.jenkins.JenkinsClient.FingerprintInfo in project platformlayer by platformlayer.
the class JenkinsCasStore method findArtifact.
@Override
public CasStoreObject findArtifact(Md5Hash hash) throws OpsException {
try {
FingerprintInfo fingerprint = client.findByFingerprint(hash.toHex());
if (fingerprint == null) {
return null;
}
BuildId build = fingerprint.getOriginalBuild();
if (build == null) {
build = fingerprint.getFirstUsage();
if (build == null) {
log.warn("Cannot find build for fingerprint: " + hash.toHex());
return null;
}
}
BuildInfo buildInfo = client.findBuildInfo(build);
if (buildInfo == null) {
return null;
}
String fingerprintFileName = fingerprint.getFileName();
ArtifactInfo found = buildInfo.findArtifactByFileName(fingerprintFileName);
if (found == null) {
log.warn("Could not find artifact: " + fingerprint + " in " + buildInfo);
return null;
}
URI url = found.getArtifactUrl();
return new JenkinsCasObject(this, hash, url);
} catch (JenkinsException e) {
throw new OpsException("Error communicating with Jenkins", e);
}
}
Aggregations