CINXE.COM
Use AWS CodeBuild with Codecov - AWS CodeBuild
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Use AWS CodeBuild with Codecov - AWS CodeBuild</title><meta name="viewport" content="width=device-width,initial-scale=1" /><meta name="assets_root" content="/assets" /><meta name="target_state" content="codecov-integration" /><meta name="default_state" content="codecov-integration" /><link rel="icon" type="image/ico" href="/assets/images/favicon.ico" /><link rel="shortcut icon" type="image/ico" href="/assets/images/favicon.ico" /><link rel="canonical" href="https://docs.aws.amazon.com/codebuild/latest/userguide/codecov-integration.html" /><meta name="description" content="Describes how to use CodeBuild with Codecov and upload reports and test cases to a CodeCov account for analysis." /><meta name="deployment_region" content="IAD" /><meta name="product" content="AWS CodeBuild" /><meta name="guide" content="User Guide" /><meta name="abstract" content="Describes how you can use AWS CodeBuild, an AWS service that builds your software applications in the AWS cloud." /><meta name="guide-locale" content="en_us" /><meta name="tocs" content="toc-contents.json" /><link rel="canonical" href="https://docs.aws.amazon.com/codebuild/latest/userguide/codecov-integration.html" /><link rel="alternative" href="https://docs.aws.amazon.com/id_id/codebuild/latest/userguide/codecov-integration.html" hreflang="id-id" /><link rel="alternative" href="https://docs.aws.amazon.com/id_id/codebuild/latest/userguide/codecov-integration.html" hreflang="id" /><link rel="alternative" href="https://docs.aws.amazon.com/de_de/codebuild/latest/userguide/codecov-integration.html" hreflang="de-de" /><link rel="alternative" href="https://docs.aws.amazon.com/de_de/codebuild/latest/userguide/codecov-integration.html" hreflang="de" /><link rel="alternative" href="https://docs.aws.amazon.com/codebuild/latest/userguide/codecov-integration.html" hreflang="en-us" /><link rel="alternative" href="https://docs.aws.amazon.com/codebuild/latest/userguide/codecov-integration.html" hreflang="en" /><link rel="alternative" href="https://docs.aws.amazon.com/es_es/codebuild/latest/userguide/codecov-integration.html" hreflang="es-es" /><link rel="alternative" href="https://docs.aws.amazon.com/es_es/codebuild/latest/userguide/codecov-integration.html" hreflang="es" /><link rel="alternative" href="https://docs.aws.amazon.com/fr_fr/codebuild/latest/userguide/codecov-integration.html" hreflang="fr-fr" /><link rel="alternative" href="https://docs.aws.amazon.com/fr_fr/codebuild/latest/userguide/codecov-integration.html" hreflang="fr" /><link rel="alternative" href="https://docs.aws.amazon.com/it_it/codebuild/latest/userguide/codecov-integration.html" hreflang="it-it" /><link rel="alternative" href="https://docs.aws.amazon.com/it_it/codebuild/latest/userguide/codecov-integration.html" hreflang="it" /><link rel="alternative" href="https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/codecov-integration.html" hreflang="ja-jp" /><link rel="alternative" href="https://docs.aws.amazon.com/ja_jp/codebuild/latest/userguide/codecov-integration.html" hreflang="ja" /><link rel="alternative" href="https://docs.aws.amazon.com/ko_kr/codebuild/latest/userguide/codecov-integration.html" hreflang="ko-kr" /><link rel="alternative" href="https://docs.aws.amazon.com/ko_kr/codebuild/latest/userguide/codecov-integration.html" hreflang="ko" /><link rel="alternative" href="https://docs.aws.amazon.com/pt_br/codebuild/latest/userguide/codecov-integration.html" hreflang="pt-br" /><link rel="alternative" href="https://docs.aws.amazon.com/pt_br/codebuild/latest/userguide/codecov-integration.html" hreflang="pt" /><link rel="alternative" href="https://docs.aws.amazon.com/zh_cn/codebuild/latest/userguide/codecov-integration.html" hreflang="zh-cn" /><link rel="alternative" href="https://docs.aws.amazon.com/zh_tw/codebuild/latest/userguide/codecov-integration.html" hreflang="zh-tw" /><link rel="alternative" href="https://docs.aws.amazon.com/codebuild/latest/userguide/codecov-integration.html" hreflang="x-default" /><meta name="feedback-item" content="CodeBuild" /><meta name="this_doc_product" content="AWS CodeBuild" /><meta name="this_doc_guide" content="User Guide" /><script defer="" src="/assets/r/vendor4.js?version=2021.12.02"></script><script defer="" src="/assets/r/vendor3.js?version=2021.12.02"></script><script defer="" src="/assets/r/vendor1.js?version=2021.12.02"></script><script defer="" src="/assets/r/awsdocs-common.js?version=2021.12.02"></script><script defer="" src="/assets/r/awsdocs-doc-page.js?version=2021.12.02"></script><link href="/assets/r/vendor4.css?version=2021.12.02" rel="stylesheet" /><link href="/assets/r/awsdocs-common.css?version=2021.12.02" rel="stylesheet" /><link href="/assets/r/awsdocs-doc-page.css?version=2021.12.02" rel="stylesheet" /><script async="" id="awsc-panorama-bundle" type="text/javascript" src="https://prod.pa.cdn.uis.awsstatic.com/panorama-nav-init.js" data-config="{'appEntity':'aws-documentation','region':'us-east-1','service':'codebuild'}"></script><meta id="panorama-serviceSubSection" value="User Guide" /><meta id="panorama-serviceConsolePage" value="Use AWS CodeBuild with Codecov" /></head><body class="awsdocs awsui"><div class="awsdocs-container"><awsdocs-header></awsdocs-header><awsui-app-layout id="app-layout" class="awsui-util-no-gutters" ng-controller="ContentController as $ctrl" header-selector="awsdocs-header" navigation-hide="false" navigation-width="$ctrl.navWidth" navigation-open="$ctrl.navOpen" navigation-change="$ctrl.onNavChange($event)" tools-hide="$ctrl.hideTools" tools-width="$ctrl.toolsWidth" tools-open="$ctrl.toolsOpen" tools-change="$ctrl.onToolsChange($event)"><div id="guide-toc" dom-region="navigation"><awsdocs-toc></awsdocs-toc></div><div id="main-column" dom-region="content" tabindex="-1"><awsdocs-view class="awsdocs-view"><div id="awsdocs-content"><head><title>Use AWS CodeBuild with Codecov - AWS CodeBuild</title><meta name="pdf" content="/pdfs/codebuild/latest/userguide/codebuild-user.pdf#codecov-integration" /><meta name="rss" content="aws-codebuild-user-guide-updates.rss" /><meta name="forums" content="https://repost.aws/tags/TA3PlC5MYDQLSIC8057qi90w" /><meta name="feedback" content="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=CodeBuild&topic_url=https://docs.aws.amazon.com/en_us/codebuild/latest/userguide/codecov-integration.html" /><meta name="feedback-yes" content="feedbackyes.html?topic_url=https://docs.aws.amazon.com/en_us/codebuild/latest/userguide/codecov-integration.html" /><meta name="feedback-no" content="feedbackno.html?topic_url=https://docs.aws.amazon.com/en_us/codebuild/latest/userguide/codecov-integration.html" /><meta name="keywords" content="AWS CodeBuild,CodeBuild,AWS,Developer Tools,Developer Tools Console,Developer Tools Services,Developer Tools AWS,CI/CD,continuous integration,continuous delivery,DevOps" /><script type="application/ld+json"> { "@context" : "https://schema.org", "@type" : "BreadcrumbList", "itemListElement" : [ { "@type" : "ListItem", "position" : 1, "name" : "AWS", "item" : "https://aws.amazon.com" }, { "@type" : "ListItem", "position" : 2, "name" : "AWS CodeBuild", "item" : "https://docs.aws.amazon.com/codebuild/index.html" }, { "@type" : "ListItem", "position" : 3, "name" : "User Guide", "item" : "https://docs.aws.amazon.com/codebuild/latest/userguide" }, { "@type" : "ListItem", "position" : 4, "name" : "Advanced topics", "item" : "https://docs.aws.amazon.com/codebuild/latest/userguide/advanced-topics.html" }, { "@type" : "ListItem", "position" : 5, "name" : "Use AWS CodeBuild with Codecov", "item" : "https://docs.aws.amazon.com/codebuild/latest/userguide/advanced-topics.html" } ] } </script></head><body><div id="main"><div style="display: none"><a href="/pdfs/codebuild/latest/userguide/codebuild-user.pdf#codecov-integration" target="_blank" rel="noopener noreferrer" title="Open PDF"></a></div><div id="breadcrumbs" class="breadcrumb"><a href="/index.html">Documentation</a><a href="/codebuild/index.html">AWS CodeBuild</a><a href="welcome.html">User Guide</a></div><div id="page-toc-src"><a href="#integrate-codecov">Integrate Codecov into a build project</a></div><div id="main-content" class="awsui-util-container"><div id="main-col-body"><awsdocs-language-banner data-service="$ctrl.pageService"></awsdocs-language-banner><h1 class="topictitle" id="codecov-integration">Use AWS CodeBuild with Codecov</h1><div class="awsdocs-page-header-container"><awsdocs-page-header></awsdocs-page-header><awsdocs-filter-selector id="awsdocs-filter-selector"></awsdocs-filter-selector></div><p>Codecov is a tool that measures the test coverage of your code. Codecov identifies which methods and statements in your code are not tested. Use the results to determine where to write tests to improve the quality of your code. Codecov is available for three of the source repositories supported by CodeBuild: GitHub, GitHub Enterprise Server, and Bitbucket. If your build project uses GitHub Enterprise Server, you must use Codecov Enterprise.</p><p> When you run a build of a CodeBuild project that is integrated with Codecov, Codecov reports that analyzes code in your repository are uploaded to Codecov. The build logs include a link to the reports. This sample shows you how to integrate a Python and a Java build project with Codecov. For a list of languages supported by Codecov, see <a href="https://docs.codecov.io/docs/supported-languages" rel="noopener noreferrer" target="_blank"><span>Codecov supported languages</span><awsui-icon class="awsdocs-link-icon" name="external"></awsui-icon></a> on the Codecov website.</p> <h2 id="integrate-codecov">Integrate Codecov into a build project</h2> <p>Use the following procedure to integration Codecov into a build project.</p> <div class="procedure"><h6>To integrate Codecov with your build project</h6><ol><li> <p>Go to <a href="https://codecov.io/signup" rel="noopener noreferrer" target="_blank"><span>https://codecov.io/signup</span><awsui-icon class="awsdocs-link-icon" name="external"></awsui-icon></a> and sign up for a GitHub or Bitbucket source repository. If you use GitHub Enterprise, see <a href="https://codecov.io/enterprise" rel="noopener noreferrer" target="_blank"><span>Codecov Enterprise</span><awsui-icon class="awsdocs-link-icon" name="external"></awsui-icon></a> on the Codecov website. </p> </li><li> <p> In Codecov, add the repository for which you want coverage. </p> </li><li> <p> When token information is displayed, choose <b>Copy</b>. </p> <div class="mediaobject"> <img src="/images/codebuild/latest/userguide/images/codecov-token.png" class="aws-docs-img-whiteBg aws-docs-img-padding" alt="The token information is displayed." /> </div> </li><li> <p> Add the copied token as an environment variable named <code class="code">CODECOV_TOKEN</code> to your build project. For more information, see <a href="./change-project.html#change-project-console">Change a build project's settings (console)</a>. </p> </li><li> <p> Create a text file named <code>my_script.sh</code> in your repository. Enter the following into the file: </p> <pre class="programlisting"><div class="code-btn-container"><div class="btn-copy-code" title="Copy"><awsui-icon name="copy"></awsui-icon></div></div><!--DEBUG: cli ()--><code class="">#/bin/bash bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN</code></pre> </li><li> <p> Choose the <b>Python</b> or <b>Java</b> tab, as appropriate for your build project uses, and follow these steps. </p> <awsdocs-tabs><dl style="display: none"> <dt>Java</dt><dd tab-id="java"> <div class="procedure"><ol><li> <p> Add the following JaCoCo plugin to <code>pom.xml</code> in your repository. </p> <pre class="programlisting"><div class="code-btn-container"><div class="btn-copy-code" title="Copy"><awsui-icon name="copy"></awsui-icon></div></div><!--DEBUG: cli ()--><code class=""><build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.2</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build></code></pre> </li><li> <p> Enter the following commands in your buildspec file. For more information, see <a href="./build-spec-ref.html#build-spec-ref-syntax">Buildspec syntax</a>. </p> <pre class="programlisting"><div class="code-btn-container"><div class="btn-copy-code" title="Copy"><awsui-icon name="copy"></awsui-icon></div></div><!--DEBUG: cli ()--><code class="">build: - mvn test -f pom.xml -fn postbuild: - echo 'Connect to CodeCov' - bash my_script.sh</code></pre> </li></ol></div> </dd> <dt>Python</dt><dd tab-id="python"> <p> Enter the following commands in your buildspec file. For more information, see <a href="./build-spec-ref.html#build-spec-ref-syntax">Buildspec syntax</a>. </p> <pre class="programlisting"><div class="code-btn-container"><div class="btn-copy-code" title="Copy"><awsui-icon name="copy"></awsui-icon></div></div><!--DEBUG: cli ()--><code class="">build: - pip install coverage - coverage run -m unittest discover postbuild: - echo 'Connect to CodeCov' - bash my_script.sh</code></pre> </dd> </dl></awsdocs-tabs> </li><li> <p> Run a build of your build project. A link to Codecov reports generated for your project appears in your build logs. Use the link to view the Codecov reports. For more information, see <a href="./run-build.html">Run AWS CodeBuild builds manually</a> and <a href="./cloudtrail.html">Log AWS CodeBuild API calls with AWS CloudTrail</a>. Codecov information in the build logs looks like the following: </p> <pre class="programlisting"><div class="code-btn-container"><div class="btn-copy-code" title="Copy"><awsui-icon name="copy"></awsui-icon></div></div><!--DEBUG: cli ()--><code class="nohighlight">[Container] 2020/03/09 16:31:04 Running command bash my_script.sh _____ _ / ____| | | | | ___ __| | ___ ___ _____ __ | | / _ \ / _` |/ _ \/ __/ _ \ \ / / | |___| (_) | (_| | __/ (_| (_) \ V / \_____\___/ \__,_|\___|\___\___/ \_/ Bash-20200303-bc4d7e6 路[0;90m==>路[0m AWS CodeBuild detected. <code class="replaceable">... The full list of Codecov log entries has been omitted for brevity ...</code> 路 路[0;32m->路[0m View reports at 路[0;36m<code class="replaceable">https://codecov.io/github/user/test_py/commit/commit-id</code>路[0m [Container] 2020/03/09 16:31:07 Phase complete: POST_BUILD State: SUCCEEDED</code></pre> <p> The reports look like the following: </p> <div class="mediaobject"> <img src="/images/codebuild/latest/userguide/images/codecov-report.png" class="aws-docs-img-whiteBg aws-docs-img-padding" alt="The sample reports." /> </div> </li></ol></div> <awsdocs-copyright class="copyright-print"></awsdocs-copyright><awsdocs-thumb-feedback right-edge="{{$ctrl.thumbFeedbackRightEdge}}"></awsdocs-thumb-feedback></div><noscript><div><div><div><div id="js_error_message"><p><img src="https://d1ge0kk1l5kms0.cloudfront.net/images/G/01/webservices/console/warning.png" alt="Warning" /> <strong>Javascript is disabled or is unavailable in your browser.</strong></p><p>To use the Amazon Web Services Documentation, Javascript must be enabled. Please refer to your browser's Help pages for instructions.</p></div></div></div></div></noscript><div id="main-col-footer" class="awsui-util-font-size-0"><div id="doc-conventions"><a target="_top" href="/general/latest/gr/docconventions.html">Document Conventions</a></div><div class="prev-next"><div id="previous" class="prev-link" accesskey="p" href="./how-to-create-pipeline-add-test.html">Add a test action</div><div id="next" class="next-link" accesskey="n" href="./jenkins-plugin.html">Use CodeBuild with Jenkins </div></div></div><awsdocs-page-utilities></awsdocs-page-utilities></div><div id="quick-feedback-yes" style="display: none;"><div class="title">Did this page help you? - Yes</div><div class="content"><p>Thanks for letting us know we're doing a good job!</p><p>If you've got a moment, please tell us what we did right so we can do more of it.</p><p><awsui-button id="fblink" rel="noopener noreferrer" target="_blank" text="Feedback" click="linkClick($event)" href="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=CodeBuild&topic_url=https://docs.aws.amazon.com/en_us/codebuild/latest/userguide/codecov-integration.html"></awsui-button></p></div></div><div id="quick-feedback-no" style="display: none;"><div class="title">Did this page help you? - No</div><div class="content"><p>Thanks for letting us know this page needs work. We're sorry we let you down.</p><p>If you've got a moment, please tell us how we can make the documentation better.</p><p><awsui-button id="fblink" rel="noopener noreferrer" target="_blank" text="Feedback" click="linkClick($event)" href="https://docs.aws.amazon.com/forms/aws-doc-feedback?hidden_service_name=CodeBuild&topic_url=https://docs.aws.amazon.com/en_us/codebuild/latest/userguide/codecov-integration.html"></awsui-button></p></div></div></div></body></div></awsdocs-view><div class="page-loading-indicator" id="page-loading-indicator"><awsui-spinner size="large"></awsui-spinner></div></div><div id="tools-panel" dom-region="tools"><awsdocs-tools-panel id="awsdocs-tools-panel"></awsdocs-tools-panel></div></awsui-app-layout><awsdocs-cookie-banner class="doc-cookie-banner"></awsdocs-cookie-banner></div></body></html>