Hi Jesse,

Publishing of PR status happens on SonarQube server side, asynchronously. 
Since the commit hash we are collecting currently in the pipeline is 
something transient that doesn't exists on GitHub, it is impossible to find 
the parent. We would have to collect the parent in advance directly in the 
scanner/pipeline, running some Git commands. I started to think about it, 
but I see many corner cases.

First issue is that Jenkins offers multiple PR strategies (with merge or 
not). So we would have to do some logic to find if current commit is a 
merge commit, or maybe look directly for symbolic ref 
refs/remotes/origin/${BRANCH_NAME} 
?
Second issue is that I know some users are doing some Git operations in 
their pipeline. That could affect our heuristic since our scanner may be 
called after they already manipulated the repo.

In my opinion it would be much more reliable to have the branch source 
plugin exposing it as an env variable directly. I don't think this is 
something too SonarQube specific, since this commit hash is what is needed 
to report PR status/GitHub check/Bitbucket Code Insight.

@Joseph thanks for the tips, but we would like our scanner to be used in a 
Jenkins pipeline as a "normal" command line tool. So we don't have access 
to Jenkins API, only to the job env variables, and possibly doing some Git 
operations.


Le mercredi 5 juin 2019 03:07:31 UTC+2, Jesse Glick a écrit :
>
> On Tue, Jun 4, 2019 at 5:16 PM Julien HENRY 
> <julie...@sonarsource.com <javascript:>> wrote: 
> > Is there any simple way (except some fragile local Git operation) to 
> access the original Git sha1 that triggered the PR build? In my example I 
> need to get ab86fe3afa0b9473ea9da76c87872bf89b9b5f3b 
>
> There is not currently any environmental variable for that purpose 
> that I know of. You can simply try publishing a commit status for the 
> hash you are given, and if that gives a 422 response, try its first 
> parent instead, as I suggested in the thread leading to 
>
> https://jira.sonarsource.com/browse/SONAR-10794 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/df3df1c1-5ff8-4ff7-92c4-ae08fa7ac08e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to