kmmbvnr / django-jenkins

Plug and play continuous integration with django and jenkins
GNU Lesser General Public License v3.0
945 stars 279 forks source link

Add documentation for pipeline Jenkinsfile syntax support #352

Closed GabLeRoux closed 7 years ago

GabLeRoux commented 7 years ago

I tried to integrate this into my pipeline job on jenkins. See #351 for most recent documentation :books:. ;)

I'd like to add description on how to use this plugin with the new jenkins pipeline syntax.

There is this pull request on cubertura to add support for coverage.xml from pipeline. https://github.com/jenkinsci/cobertura-plugin/pull/55

I also commented on https://github.com/jenkinsci/cobertura-plugin/issues/50#issuecomment-262419362 where I described how to use https://github.com/cwacek/cobertura-clover-transform and use clover instead of cobertura as a temp workaround, but it failed on my side.

Here's how I managed to get coverage.xml and junit.xml to work in jenkins: I cloned https://github.com/mbarrien/cobertura-plugin/tree/pipeline (pipeline branch, that's the pr 55 above), compiled the plugin:

git clone https://github.com/mbarrien/cobertura-plugin/
cd cobertura-plugin
mvn install

This generated the .hpi plugin which I installed from Jenkins -> Manage Jenkins -> Configure Plugins -> Advanced and installed Cobertura plugin from there.

My app name is in PROJECT_APPS tuple as requested by django-jenkins. Here's what my Jenkinsfile looks like:

try {
sh '''
  #!/usr/bin/env sh
  source venv/bin/activate
  python manage.py jenkins --enable-coverage
'''
currentBuild.result = 'SUCCESS'
} catch(Exception err) {
currentBuild.result = 'FAILURE'
}

// Cobertura test coverage
step([$class: 'CoberturaPublisher', coberturaReportFile: 'reports/coverage.xml'])

// JUnit test results
step([$class: 'JUnitResultArchiver', testResults: 'reports/junit.xml'])

Everything seems to work fine: image

But there's one thing left I'm still fighting with, I created an issue on Cobertura's side: https://github.com/jenkinsci/cobertura-plugin/issues/61 I'd be very happy if someone has an idea on this!

ahmed1490 commented 7 years ago

+1

SalahAdDin commented 7 years ago

👍

kmmbvnr commented 7 years ago

Till we have a support from the Jenkins side, it can't be fixed by django-jenkins

GabLeRoux commented 7 years ago

The commits done here: https://github.com/jenkinsci/cobertura-plugin/pull/55#issuecomment-274665570

Should fix the covertura problem I had in jenkinsci/cobertura-plugin#61 when using jenkinsfile, and I still think it'd be great to improve documentation as I managed to get this working, but it's not docuemnted anywhere. ;)

kyrsideris commented 7 years ago

Just a small change when building the Cobertura modified plugin, don't forget to checkout the pipeline branch:

git clone https://github.com/mbarrien/cobertura-plugin/
cd cobertura-plugin
git checkout pipeline
mvn install

:)

SalahAdDin commented 7 years ago

So good

ctssatish commented 6 years ago

i am using Jacoco plugin for code coverage its showing 0.0% coverage in Sonar UI, I am using Jenkins pipeline jobs by using Groovy script