How to get project name from Gitlab webhook event payload

1k views Asked by At

I am using event payload at Jenkins side to run sonar scan, for this, I need project name variable. In Gitlab request, I can see that project details are sent to Jenkins but in Jenkins when I echo environment I can only see below properties.

gitlabActionType
gitlabBranch
gitlabMergedByUser
gitlabMergeRequestId
gitlabMergeRequestIid
gitlabMergeRequestLastCommit
gitlabMergeRequestState
gitlabMergeRequestTargetProjectId
gitlabMergeRequestTitle
gitlabSourceBranch
gitlabSourceNamespace
gitlabSourceRepoHomepage
gitlabSourceRepoHttpUrl
gitlabSourceRepoName
gitlabSourceRepoSshUrl
gitlabSourceRepoURL
gitlabTargetBranch
gitlabTargetNamespace
gitlabTargetRepoHttpUrl
gitlabTargetRepoName
gitlabTargetRepoSshUrl
gitlabUserEmail
gitlabUserName

How can I get project name?

1

There are 1 answers

0
VonC On

You won't have it through a JSON payload send by a (GitLab) webhook, since GitLab knows nothing about Sonar (natively).

You need to deduce the Sonar project name from the files of the project themselves.

Typically (for instance) a Maven project would use the pom.xml project name as its Sonar project name: see "Is it possible to tell Sonar the project name from the command line?".