问题
In Jenkins I'm using the XML API to get the SHA(s) of a commit, e.g.
http://jenkins/view/job/test/470/api/xml?xpath=//lastBuiltRevision/SHA1&wrapper=SHAS
I put it in a wrapper because often it contains more than one SHA and I'm going to process these further.
However one of the SHAs always is invalid...
<SHAS>
<SHA1>cbf26ebac6b4b3860a794c0b1ad86758e7757a3a</SHA1>
<SHA1>7e861132ce428911585a818107ba35c44cf12bbf</SHA1>
</SHAS>
The second SHA is fine but when I check the first SHA here on our GIT repo commits it leads to an error page:
Commit 'cbf26ebac6b4b3860a794c0b1ad86758e7757a3a' does not exist in repository 'test'.
Does anyone know why we get invalid SHAs on Jenkins and how to resolve this issue?
UPDATE:
The complete lastBuiltRevision ...
<wrapped>
<lastBuiltRevision>
<SHA1>cbf26ebac6b4b3860a794c0b1ad86758e7757a3a</SHA1>
<branch>
<SHA1>cbf26ebac6b4b3860a794c0b1ad86758e7757a3a</SHA1>
<name>origin/master</name>
</branch>
</lastBuiltRevision>
<lastBuiltRevision>
<SHA1>7e861132ce428911585a818107ba35c44cf12bbf</SHA1>
<branch>
<SHA1>7e861132ce428911585a818107ba35c44cf12bbf</SHA1>
<name>refs/remotes/origin/develop</name>
</branch>
</lastBuiltRevision>
</wrapped>
回答1:
My guess is that the scm plugin parses the build log after the build run to extract the revision data. If you use the Multiple SCM plugin, a Jenkins Pipeline with multiple git
or checkout
commands or a Jenkins Shared Library it is very well possible to end up with multiple scm revisions from multiple repositories (we currently have 6 in our of jobs...).
I don't know if it is possible to ignore parts of the log for the SCM revision parsing, otherwise you'll have to do some filtering on your side of the request. If the different revisions happen in order in the log, then you can choose to always discard the first or second one.
回答2:
One possible case is when:
- Jenkins records a SHA1 for origin/master in its
lastBuiltRevision
- someone force push (
git push --force
) and overwrite the SHA1 with a new history
来源:https://stackoverflow.com/questions/46045821/jenkins-invalid-git-revisions