Skip to content

Commit 4619c20

Browse files
committed
Fixes #430: Validate an artifact using the "hash" rather than "fileName".
Jenkins only stores one version of an artifact by its hash and by the original filename. Subsequent stores of an artifact with an identical hash but different filename will point to the original artifact. If a duplicate artifact (identical hash) has a different filename than the original filename then that new filename will be stored as a name in the build artifacts but will not change the fileName of the original artifact. This makes it problematic to compare against the original fileName when validating a build artifact that has been saved. Since the md5sum hash is computed for the local, saved artifact it can be compared against the Jenkins artifact ID (viz hash) for validation. This avoids the problem of identical artifacts having additional filenames. Using the hash is also a better way of validating data integrity rather than using the fileName even when the filename matches.
1 parent 4494278 commit 4619c20

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Diff for: jenkinsapi/fingerprint.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def valid(self) -> bool:
7171
return True
7272

7373
def validate_for_build(self, filename: str, job: str, build: int) -> bool:
74+
_ = filename # Currently unused
7475
if not self.valid():
7576
log.info("Fingerprint is not known to jenkins.")
7677
return False
@@ -81,10 +82,10 @@ def validate_for_build(self, filename: str, job: str, build: int) -> bool:
8182
if self._data["original"]["name"] == job:
8283
if self._data["original"]["number"] == build:
8384
return True
84-
if self._data["fileName"] != filename:
85+
if self._data["hash"] != self.id_:
8586
log.info(
86-
msg="Filename from jenkins (%s) did not match provided (%s)"
87-
% (self._data["fileName"], filename)
87+
msg="File hash from Jenkins (%s) did not match local hash (%s)"
88+
% (self._data["hash"], self.id_)
8889
)
8990
return False
9091
for usage_item in self._data["usage"]:

0 commit comments

Comments
 (0)