1

Background

After a lot of hard work we finally got a Jenkins CI pulling code from out GitHub repositories and are now doing Continuous Integration as well as Deployment.

We get the code and only deploy it if all the tests pass, as usual.

Now I have checked that there are a number of plugins for Java that besides running the tests, also do test coverage, like Cobertura.

But we don't use Java. We use Elixir.

In the Elixir world, we have excoveralls, which is a facade for the coveralls API. The coveralls API supports jenkins so it stands to reason I would find a Coveralls Plugin for Jenkins.

I was wrong. There is nothing.

Questions

So now I have a test coverage metric that is basically useless because I can't integrate it with Jenkins.

Are there any Erlang/Elixir plugins one can use with Jenkins for code coverage?

I also created a Issue in the projects ( which seems to be abandoned ... ) https://github.com/parroty/excoveralls/issues/167

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266

3 Answers3

1

I have a stage to publish the coverage on my Jenkinsfile. I'm not sure if that is the metric that you want but...

stage('Publish Coverage') {
  when{
    branch 'master'
  }

  steps {
    publishHTML target: [
      allowMissing: true,
      alwaysLinkToLastBuild: true,
      keepAll: true,
      reportDir: 'cover',
      reportFiles: 'excoveralls.html',
      reportName: 'Coverage Report'
    ]
  }
}
Marcos Tapajós
  • 546
  • 2
  • 8
  • 1
    I am afraid that is not what I want. What I want is to be able to see coverage reports of a given branch in Jenkins, like Cobertura or, Jacoco: https://wiki.jenkins.io/display/JENKINS/JaCoCo+Plugin . You can check how this plugin enhances Jenkins with new functionality. This is what I want. – Flame_Phoenix Dec 18 '18 at 15:52
  • Thanks for clarifying that. I'm going to take a look how those plugins works. – Marcos Tapajós Dec 19 '18 at 16:07
1

I have found 2 ways of doing this:

  1. Using Hex package JUnit formatter together with junit post pipeline step
  2. Using covertool together with Cobertura Jenkins pluing

Option 1

This solution works and is quite nice. It forces me to change the test_helper.exs but that is a minor inconvenience overall. It is nice but it only offers the most basic of reports and for me this is where it fails.

Option 2

The option I decided to go with. Yes, making the Jenkinsfile work for Cobertura was a nightmare, specially because in previous versions it was not even possible and because there is contradictory information scattered all over the place.

However, once you get that Jenkinsfile going, you get to rip those sweet reports from Cobertura. Cobertura was made with Java in mind, there is no two ways about it. In the reports you see things like Class coverage and such, but you can easily translate that do modules. The interface offers a lot more information and tracks coverage over time, which is something I actually want.

For future notice, here is my Jenkinsfile:

pipeline {
  agent any

  environment { 
    SOME_VAR = "/home/deployer"
  }

  stages {
    stage("Build") {
      steps {
        sh "MIX_ENV=test mix do deps.get, deps.compile"
      }
    }

    stage("Test") {
      steps {
        sh "mix test --cover"
      }
    }

    stage("Credo"){
      steps{
        sh "mix credo --strict"
      }
    }

    stage("Deploy"){
      when{
        expression{
          env.BRANCH_NAME == "master"
        }
      }
      steps{
        sh '''
         echo "Deploy with AWS or GCP or whatever"                                                         
        '''
      }
    }

  }

  post{
    always{
      cobertura coberturaReportFile: "coverage.xml"
    }
  }
}

Of notice: 1. I am extremely Nazi with my code, so I also use Credo. You can further configure it as to not blow the entire pipeline because you missed a new line at the end of file but as I said, I am quite Nazi with my code. 2. The Deploy stage only runs if the pushed branch is Master. There are other ways of doing this, but I found it that having this way for a small project was good enough.

Overall I like covertools for now but I don't know if the first solution has the same potential. At least I didn't see it.

Hope this post helps!

Original thread:

Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
0

Another way to post coverage from Jenkins for Elixir project is using ExCoveralls option mix coveralls.post. This allows you to post the coverage from any host, including your Jenkins server. Based on the example on this Jenkins tutorial page, you can write in Jenkinsfile like this:

pipeline {
  agent any
  stages {
      // Assuming all environment variables are set beforehand
      stage('run unit test') {
          steps {
              sh 'echo "Run Unit Test and Post coverage"'
              sh '''
                MIX_ENV=test mix coveralls.post --token $COVERALLS_REPO_TOKEN --sha $GIT_COMMIT --branch $GIT_BRANCH --name "jenkins" --message $GIT_COMMIT_MSG
              '''
          }
      }
   }
}