# How to submit code coverage results to codecov/coveralls via GitLab CI?

**URL:** <https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503>\
**Category:** General Usage\
**Tags:** package, coverage, ci, gitlab\
**Created:** [June 20, 2019, 9:59pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503 "2019-06-20T21:59:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 20, 2019, 9:59pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/1 "2019-06-20T21:59:29Z")

</div>

Hi everyone,

I’m working on developing my first Julia package, and I want to make sure I have the code coverage aspect down before committing to developing and hosting the package on GitLab (which I prefer for a few reasons). I’ve seen some examples of how to submit code coverage results to codecov and coveralls using the Travis CI in Github, but for my project, I’m planning to use GitLab’s built-in CI. Can I simply add

```julia
after_success:
  - julia -e 'cd(Pkg.dir("PkgName")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

```

to my .gitlab-ci.yml file just as I would to a .travis.yml file? (and add the codecov token to my environment variables in gitlab?)

Thanks for any help!

- Vincent

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 21, 2019, 4:45am UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/2 "2019-06-21T04:45:04Z")

</div>

I created a package recently and the [.travis.yml of it](https://github.com/henriquebecker91/TrackingHeaps.jl/blob/master/.travis.yml) works. I think you need to give Travis and Codecov permission to access your repository (something like that), and Travis has a web interface that shows you in real time the output of the build when you commit a new version (to help you debug why it is not working). I had never done that before and I have to admit that I suffered a little to make it working. Until I discovered the Travis web interface it was not working because the yml was wrongly indented and I did not know. My commit history shows in that file shows my suffering.

Also, you probably need import `Pkg` before using it.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 21, 2019, 5:09am UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/3 "2019-06-21T05:09:07Z")

</div>

I got an e-mail about an issue you opened at

> **[Tamas K. Papp / GitlabJuliaDemo.jl · GitLab](https://gitlab.com/tkpapp/GitlabJuliaDemo.jl)**
>
> Example for setting up CI with Julia on Gitlab.

but then I cannot find it in the list of issues. Weird.

In any case, I explore and add @Henrique_Becker’s solution to the template.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 21, 2019, 5:11am UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/4 "2019-06-21T05:11:07Z")

</div>

Are you sure this works on **Gitlab**? Your repo is on **Github**.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [June 21, 2019, 5:31am UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/5 "2019-06-21T05:31:30Z")

</div>

I am very sorry, I have read the e-mail when I was tired and did not notice that it was GitLab specific. My bad.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 21, 2019, 4:43pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/6 "2019-06-21T16:43:42Z")

</div>

Thanks for the replies! Hmm, looks like the authors of the [CuArrays.jl](https://github.com/JuliaGPU/CuArrays.jl) repo may have it figured out? It’s hosted on GitHub, but uses GitLab CI and publishes coverage to [codecov.io](http://codecov.io). I’ll reach out to them and post back to this thread if they have a solution!

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 21, 2019, 7:02pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/7 "2019-06-21T19:02:04Z")

</div>

Looks like Coverage.jl doesn’t have support for direct integration with GitLab CI. I opened an issue here: [https://github.com/JuliaCI/Coverage.jl/issues/226](https://github.com/JuliaCI/Coverage.jl/issues/226)

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 21, 2019, 8:38pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/8 "2019-06-21T20:38:14Z")

</div>

Alright! I got it figured out. Turns out even though Coverage.jl doesn’t have support for GitLab, you can still publish results to [codecov.io](http://codecov.io) by adding this:

```julia
after_script:
  - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit_local(process_folder())

```

to the .gitlab-ci.yml file, and making sure you’ve added an environment variable to your gitlab project under _settings ▶ CI/CD ▶ variables_ with key “CODECOV\_TOKEN” and value set to the repository upload token provided by codecov. Make sure you don’t put quotes around the value either!

@Tamas_Papp If you want I can fork your GitLab example repo and put in a merge request with the necessary additions (but you’ll need to add the codecov token).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 22, 2019, 4:40am UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/9 "2019-06-22T04:40:19Z")

</div>

A merge request would be appreciated. The instructions above should go in the README, too. I will of course add a token.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 24, 2019, 5:01pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/10 "2019-06-24T17:01:54Z")

</div>

@Tamas_Papp I changed so much in my forked repo (and so lots would be changed if I merged it) that I think it might make the most sense for you to just update the yml file in your repo manually. Here’s the code:

```julia
image: julia:1.1 # image comes from Docker hub

before_script:
  # workaround for https://github.com/JuliaDocs/Documenter.jl/issues/686
  - apt-get -qq update; apt-get -y install git
  - julia --project=@. -e "import Pkg; Pkg.build()"

default:
  script:
    - julia --project=@. -e "import Pkg; Pkg.test(; coverage = true)"
    - julia --project=test/coverage -e 'import Pkg; Pkg.instantiate()'
    - julia --project=test/coverage test/coverage/coverage-summary.jl

pages:
  stage: deploy
  script:
    - julia --project=docs -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
    - julia --project=docs --color=yes docs/make.jl
    - mv docs/build public # move to the directory picked up by Gitlab pages
  artifacts:
    paths:
      - public
  only:
  - master

after_script:
  - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit_local(process_folder())'

```

As you can see I only had to add the one line. You can find the badge URL in codecov under settings for the project.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 24, 2019, 5:53pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/11 "2019-06-24T17:53:11Z")

</div>

It took a bit more than that, but now I fixed this in the repo. Thanks for investigating this.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 24, 2019, 6:01pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/12 "2019-06-24T18:01:10Z")

</div>

@Tamas_Papp Sure thing! What else did you have to do aside from adding the token and initializing the codecov project? Just want to cover all the bases in this thread so others can use it in the future.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 24, 2019, 7:40pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/13 "2019-06-24T19:40:02Z")

</div>

You can see the MR here:

> **[codecov integration (!3) · Merge requests · Tamas K. Papp / GitlabJuliaDemo.jl...](https://gitlab.com/tkpapp/GitlabJuliaDemo.jl/-/merge_requests/3/diffs)**
>
> Fixes #4....

Basically, it would not run without the codecov file for me, and one does not need an additional script to submit, since we use the Project.toml-based framework as on Travis. This is also faster since the coverage info is calculated already.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [June 24, 2019, 7:57pm UTC](https://discourse.julialang.org/t/how-to-submit-code-coverage-results-to-codecov-coveralls-via-gitlab-ci/25503/14 "2019-06-24T19:57:36Z")

</div>

Ah I see, you just added the coverage submission to the coverage script in test/coverage. In my case, I don’t have a coverage script at all since I’m just using codecov, so I stuck with using the after\_script command in the yml. Interestingly I didn’t need a codecov.yml, but will keep it in mind in case I run into problems in the future. Thanks for your help with all of this!
