ciricihq / gitlab-sonar-scanner

This project is no longer maintained
GNU General Public License v3.0
80 stars 62 forks source link

Automatically define sonar variables based on gitlab ci ones (if they are not defined) #10

Closed elboletaire closed 6 years ago

elboletaire commented 7 years ago

Automatically define SONAR_PROJECT_VERSION from $CI_BUILD_ID if SONAR_PROJECT_VERSION has not been defined by the user (in .gitlab-ci.yml).

More:

albarji commented 7 years ago

Would it make sense to do the same for the SONAR_GITLAB_PROJECT_ID - $CI_PROJECT_ID and SONAR_PROJECT_KEY - $CI_PROJECT_NAME? I'm finding I have to include these bindings as well in my .gitlab-ci.ymlfiles.

elboletaire commented 7 years ago

Ofc it can be done. The reason why we didn't think about it is because we use different identifiers in sonar than in gitlab.

elboletaire commented 6 years ago

@albarji this is already available in the develop tag, could you help us trying it and letting us know if it works as expected for you?

Thanks in advance 😃

elboletaire commented 6 years ago

Mmm... ok I'm having some issues with the develop version, I'll let you know when it's ready for using it.

elboletaire commented 6 years ago

Now everything works as expected. So if anyone wanna try... go for it.

albarji commented 6 years ago

Took me some time to check this out. Thanks for the changes!

I'm finding something troubling though. The SONAR_PROJECT_KEY environment variable is now not being processed anymore (as per this commit), so I guess the proper way to deal with this now is to add it to the sonar-project.properties file. My question is: wouldn't it be easier to assign SONAR_PROJECT_KEY=$CI_PROJECT_NAME so that the name of the project is automatically fetched from Gitlab and assigned to a Sonar project with the same name?

elboletaire commented 6 years ago

We removed it due to #19. The proper way would be using the sonar-project.properties file (that's how we always have done it), or specifying the param, as it's now possible with the latest changes:

script:
- gitlab-sonar-scanner -Dsonar.projectKey=Whatever

The problem is that there's a lot of people using different ids in CI_PROJECT_NAME and SONAR_PROJECT_KEY. In our case, we use a lot of namespaces and many projects have the exact same name (like 'api' or 'widgets'), which does not fit for our needs. It also was overlapping the field defined in the sonar-project.properties file, so unless you find a solution... it'll remain this way.

albarji commented 6 years ago

I see, that makes sense. Well, fortunately for my use case I followed your suggestion and used

script:
    - gitlab-sonar-scanner -Dsonar.projectKey=$CI_PROJECT_NAME

This worked out perfectly. Thanks a lot!