{"id":4325,"date":"2020-12-13T14:41:18","date_gmt":"2020-12-13T20:41:18","guid":{"rendered":"https:\/\/coderrect.com\/?post_type=docs&p=4325"},"modified":"2021-09-04T05:43:36","modified_gmt":"2021-09-04T11:43:36","slug":"ci-cd-integration-and-installation","status":"publish","type":"docs","link":"https:\/\/coderrect.com\/docs\/ci-cd-integration-and-installation\/","title":{"rendered":"CI\/CD Integration and Installation"},"content":{"rendered":"\n
<\/p>\n\n\n\n
This tutorial shows how to integrate Coderrect with Jenkins<\/a>, the most popular CI\/CD platform.<\/p>\n\n\n\n Coderrect<\/strong> is a static analysis tool for C\/C++ code. Unlike popular tools such as Cppcheck<\/a> and Clang static analyzer<\/a>, one of the powerful features of Coderrect is the detection of concurrency races caused by code using explicit multi-thread APIs (e.g. PThread<\/a>, std::thread<\/a>) or implicit parallel APIs (e.g. OpenMP<\/a>). <\/p>\n\n\n\n Besides running Coderrect to scan the local source code via the command line, you can easily integrate it with Jenkins to include it in your CI\/CD pipeline so that Coderrect can be triggered automatically by a pull request, a code check-in, or a scheduled nightly build.<\/p>\n\n\n\n The diagram below illustrates the interaction among components in Coderrect-Jenkins integration.<\/p>\n\n\n\n When a build is scheduled Jenkins master asks Jenkins agents to prepare the source code (usually pull the latest code from a source control system), build the project, test and analysis the program. <\/p>\n\n\n\n Upon receiving the request from Jenkins Master, the Jenkins agent runs Coderrect installed locally to analyze the code and report discoveries back to the master. <\/p>\n\n\n\n The first step is to install the Coderrect package to the Jenkins agent machine. Note that Coderrect just supports Linux for now. <\/p>\n\n\n\n You can download Coderrect Jenkins plugin here. Then go to the \u201cAdvanced<\/strong>\u201d tab of \u201cManage Plugins<\/strong>\u201d page.<\/p>\n\n\n\n For \u201cUpload Plugin\u201d, click \u201cChoose File<\/strong>\u201d to select the downloaded coderrect.hpi<\/strong>. <\/p>\n\n\n\n Now we can create a multi-branch project in Jenkins.<\/p>\n\n\n\n Go to Jenkins portal and click \u201cNew Item<\/strong>\u201c.<\/p>\n\n\n\n Enter the project name and select \u201cMultibranch Pipeline<\/strong>\u201d <\/p>\n\n\n\n Set up the source control and build information. Make sure you use Jenkinsfile to control the build pipeline.<\/p>\n\n\n\n We already created a project in Jenkins. To let Jenkins know how to build, test and analyze the code, we have to create a file called Jenkinsfile under the root directory of your repository.<\/p>\n\n\n\n The Jenkinsfile above defines a pipeline with two stages. The \u201cbuild\u201d stage builds the project and runs coderrect to analyze the generated binary. The \u201canalysis\u201d stage reports the analysis results to the master.<\/p>\n\n\n\n You may be aware that the command \u201cpublishCoderrect\u201d has a parameter whose value is \u201c\u201d in our example. What is it? It is the relative path (to the project root directory) where you executes \u201ccoderrect\u201d. We execute \u201ccoderrect\u201d immediately under the project root so that we specify its value to \u201c\u201d.<\/p>\n\n\n\n If we execute \u201ccoderrect\u201d under a directory rather than the project root we need to set up this parameter correctly. For example, the following figure shows typical build steps for a cmake-based project:<\/p>\n\n\n\n In this case you execute \u201ccoderrect\u201d under project-root\/build<\/em><\/strong>. You need to set the build directory to \u201cbuild\u201d.<\/p>\n\n\n\n Now we are done! We can go to the project dashboard and manually trigger a build.<\/p>\n\n\n\n Coderrect adds a section into the build summary page. The section shows the number of races in different categories for this build and the previous build. For example, the demo project above has 13 data races.<\/p>\n\n\n\n You can click the \u201cCoderrect\u201d item in the navigation bar to see details.<\/p>\n\n\n\n The detail report has three views \u2013 full, new and solved. The \u201cfull\u201d view shows all races found from the current build. The \u201cnew\u201d view shows just races introduced by the new committed code since previous build. The \u201csolved\u201d view shows races fixed by the new code.<\/p>\n\n\n\n I hope you enjoy this post. Please send to feedback@coderrect.com if you have any feedback.<\/p>\n\n\n\n This tutorial shows how to integrate Coderrect with Jenkins<\/a>, the most popular CI\/CD platform.<\/p>\n\n\n\n Coderrect<\/strong> is a static analysis tool for C\/C++ code. Unlike popular tools such as Cppcheck<\/a> and Clang static analyzer<\/a>, one of the powerful features of Coderrect is the detection of concurrency races caused by code using explicit multi-thread APIs (e.g. PThread<\/a>, std::thread<\/a>) or implicit parallel APIs (e.g. OpenMP<\/a>). <\/p>\n\n\n\n Besides running Coderrect to scan the local source code via the command line, you can easily integrate it with Jenkins to include it in your CI\/CD pipeline so that Coderrect can be triggered automatically by a pull request, a code check-in, or a scheduled nightly build.<\/p>\n\n\n\n The diagram below illustrates the interaction among components in Coderrect-Jenkins integration.<\/p>\n\n\n\n When a build is scheduled Jenkins master asks Jenkins agents to prepare the source code (usually pull the latest code from a source control system), build the project, test and analysis the program. <\/p>\n\n\n\n Upon receiving the request from Jenkins Master, the Jenkins agent runs Coderrect installed locally to analyze the code and report discoveries back to the master. <\/p>\n\n\n\n The first step is to install the Coderrect package to the Jenkins agent machine. Note that Coderrect just supports Linux for now. <\/p>\n\n\n\n You can download Coderrect Jenkins plugin file here<\/a>. Then go to the \u201cAdvanced<\/strong>\u201d tab of \u201cManage Plugins<\/strong>\u201d page.<\/p>\n\n\n\n For \u201cUpload Plugin\u201d, click \u201cChoose File<\/strong>\u201d to select the downloaded coderrect.hpi<\/strong>. <\/p>\n\n\n\n Now we can create a freestyle project in Jenkins.<\/p>\n\n\n\n Go to Jenkins portal and click \u201cNew Item<\/strong>\u201c.<\/p>\n\n\n\n Enter the project name (TDEngine here) and select \u201cFreestyle project<\/strong>\u201d <\/p>\n\n\n\n Set up the source control and build information. For the build stage, I create the following script commands<\/p>\n\n\n\n The last step \u201ccoderrect -e taosd -t make\u201d tells coderrect to<\/p>\n\n\n\n Set up the post-build stage by choosing \u201cPublish the race report to Jenkins\u201d<\/p>\n\n\n\n Since we run \u201ccoderrect\u201d under the project_root\/build<\/em><\/strong>, we specify a relative path \u201cbuild<\/em><\/strong>\u201d so that coderrect knows where to find the race report.<\/p>\n\n\n\n You are ready to go ffter you click \u201cSave\u201d!<\/p>\n\n\n\n Coderrect adds a section into the build summary page. The section shows the number of races in different categories for this build and the previous build. For example, the demo project above has 13 data races.<\/p>\n\n\n\n You can click the \u201cCoderrect\u201d item in the navigation bar to see detail report.<\/p>\n\n\n\n The detail report has three views \u2013 full, new and solved. The \u201cfull\u201d view shows all races found from the current build. The \u201cnew\u201d view shows just races introduced by the new committed code since previous build. The \u201csolved\u201d view shows races fixed by the new code.<\/p>\n\n\n\n I hope you enjoy this post. Please send to feedback@coderrect.com if you have any feedback.<\/p>\n\n\n\n If you are already running a CI<\/a>\/<\/a>CD<\/a> service on Github<\/a>, it is easy to add Coderrect to your workflows<\/a>. In a nutshell, add the following to .github\/workflows\/ci.yml<\/em><\/strong><\/p>\n\n\n\n Continuous Integration\/Continuous Delivery (CI<\/em>\/CD<\/em>) is a common practice now for developing software. In CI, typically tests and checks are run against every pull request and code commit to ensure the new code changes do not break anything or introduce new bugs. CI makes it easier to fix bugs quickly and often.<\/p>\n\n\n\n If your code is hosted on Github, you can create custom CI\/CD workflows directly in your GitHub repository with GitHub Actions<\/a>. All you need is to add a .yml file under .github\/workflows\/<\/em><\/strong> of your Github repo.<\/p>\n\n\n\n As an example, Redis<\/a> has a ci.yml file<\/a> with the following content:<\/p>\n\n\n\n With the configuration above, Github CI will build and test Redis upon every code push and pull request. If the build is successful and the tests are all passed, Github will show a green tick associated with the commit. <\/p>\n\n\n\n Otherwise, if the build or any test fails, you will see a red cross: <\/p>\n\n\n\n To run coderrect in the Github CI, in ci.yml, simply add the following three steps:<\/p>\n\n\n\n In Step 1, coderrect is setup; <\/p>\n\n\n\n In Step 2, the flag -analyzeAllBinaries<\/strong><\/em> tells Coderrect to check all the build targets;<\/p>\n\n\n\n In Step 3, if any race is detected the results will be reported in the CI terminal. A red cross sign will be shown, indicating potential race hazards found by Coderrect: <\/p>\n\n\n\n To see the detailed race information, just click the arrow sign to expand it: <\/p>\n\n\n\n Coderrect only needs to be downloaded once for Github CI. To cache the downloaded Coderrect package, simply add the following to ci.yml.<\/p>\n\n\n\n A full example is available at here<\/a>.<\/p>\n\n\n\n Spack<\/a> is an increasingly popular package manager for Linux and macOS that eliminates the difficulties of managing complex software dependencies. Spack is especially popular in the high performance computing community. Spack won the prestigious R&D 100 Award<\/a> in 2019 and is the official deployment tool<\/a> of the ExaScale Computing Project<\/a> which is tasked finding the tools and systems to support the next generation of ExaScale super computers in the U.S. Spack can even be used to set up a cloud-HPC cluster in AWS<\/a>.<\/p>\n\n\n\n This tutorial assumes you already have Spack installed. If you are new to Spack, we recommend following Spack\u2019s Getting Started Guide<\/a>.<\/p>\n\n\n\n First download<\/a> and add the Coderrect Spack repository to your local machine.<\/p>\n\n\n\n Once the repo is registered, Spack makes its easy to install and load the Coderrect tool.<\/p>\n\n\n\n Coderrect is now installed and ready to use. Spack really does make things simple!<\/p>\n\n\n\n Check out the Coderrect Quick Start<\/a> page or some of the other tutorials<\/a> to see examples of how to use the Coderrect tool.<\/p>\n","protected":false},"excerpt":{"rendered":" CI\/CD Integration and Installation Coderrect and Jenkins Integration (Using Jenkinsfile) This tutorial shows how to integrate Coderrect with Jenkins, the most popular CI\/CD platform. Coderrect is a static analysis tool for C\/C++ code. Unlike popular tools such<\/p>\n","protected":false},"author":182999572,"featured_media":0,"parent":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false},"doc_category":[1414],"doc_tag":[],"jetpack_likes_enabled":false,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/docs\/4325"}],"collection":[{"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/users\/182999572"}],"replies":[{"embeddable":true,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/comments?post=4325"}],"version-history":[{"count":17,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/docs\/4325\/revisions"}],"predecessor-version":[{"id":5682,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/docs\/4325\/revisions\/5682"}],"wp:attachment":[{"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/media?parent=4325"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/doc_category?post=4325"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/coderrect.com\/wp-json\/wp\/v2\/doc_tag?post=4325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\n\n\n
\n\n\n\nOverview<\/h4>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nInstall Coderrect<\/h4>\n\n\n\n
\n\n\n\nInstall Coderrect Jenkins Plugin<\/h4>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nCreate a multi-branch project<\/h4>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nCreate Jenkinsfile<\/h4>\n\n\n\n
pipeline {\n agent any\n\n stages {\n stage('Build') {\n steps {\n sh \"coderrect make\"\n }\n }\n\n stage('Analysis') {\n steps {\n publishCoderrect \"\"\n }\n }\n }\n}<\/pre>\n\n\n\n
# we are under the project root directory\nmkdir build\ncd build\ncmake ..\ncoderrect make<\/pre>\n\n\n\n
#pipeline {\n agent any\n\n stages {\n stage('Build') {\n steps {\n sh \"mkdir build && cd build && cmake .. && coderrect make\"\n }\n }\n\n stage('Analysis') {\n steps {\n publishCoderrect \"build\"\n }\n }\n }\n}<\/pre>\n\n\n\n
\n\n\n\nTrigger a Build<\/h4>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nCoderrect and Jenkins Integration (Using freestyle project)<\/h2>\n\n\n\n
\n\n\n\n
\n\n\n\nOverview<\/h3>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nInstall Coderrect<\/h3>\n\n\n\n
\n\n\n\nInstall Coderrect Jenkins Plugin<\/h3>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nCreate a Freestyle project<\/h3>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nTrigger a Build<\/h3>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nGithub CI\/CD Integration<\/h2>\n\n\n\n
- name: coderrect setup\n run: |\n wget https:\/\/public-installer-pkg.s3.us-east-2.amazonaws.com\/coderrect-linux-1.1.3.tar.gz\n tar zxf coderrect-linux-1.1.3.tar.gz\n echo \"$PWD\/coderrect-linux-1.1.3\/bin\" >> $GITHUB_PATH\n- name: make\n run: coderrect -analyzeAllBinaries make\n- name: coderrect check\n run: coderrect -publishResults<\/pre>\n\n\n\n
\n\n\n\nBackground<\/h3>\n\n\n\n
name: CI\non: [push, pull_request]\njobs:\n test-ubuntu-latest:\n runs-on: ubuntu-latest\n steps:\n - uses: actions\/checkout@v2\n - name: make\n run: make\n - name: test\n run: |\n sudo apt-get install tcl8.5\n .\/runtest --verbose\n - name: module api test\n run: .\/runtest-moduleapi --verbose<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nIntegrating Coderrect into Github CI<\/h3>\n\n\n\n
# Step 1: download coderrect and add to path\n- name: setup coderrect\n run: |\n wget https:\/\/public-installer-pkg.s3.us-east-2.amazonaws.com\/coderrect-linux-0.8.0.tar.gz\n tar zxf coderrect-linux-0.8.0.tar.gz\n echo \"::add-path::$PWD\/coderrect-linux-0.8.0\/bin\"<\/pre>\n\n\n\n
# Step 2: build and run coderrect\n- name: make\n run: coderrect -analyzeAllBinaries make<\/pre>\n\n\n\n
# Step 3: coderrect results\n- name: coderrect check\n run: coderrect -publishResults<\/pre>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
\n\n\n\nCache the downloaded Coderrect<\/h3>\n\n\n\n
- name: cache coderrect\n id: cache-coderrect\n uses: actions\/cache@v2\n with:\n path: coderrect-linux-0.8.0\n key: ${{ runner.os }}-coderrect\n\n- name: setup coderrect\n if: steps.cache-coderrect.outputs.cache-hit != 'true'<\/pre>\n\n\n\n
\n\n\n\nInstalling Coderrect with Spack<\/h2>\n\n\n\n
\n\n\n\nPrerequisites<\/h3>\n\n\n\n
\n\n\n\nInstalling Coderrect with Spack<\/h3>\n\n\n\n
$ wget https:\/\/github.com\/coderrect-inc\/coderrect-spack\/archive\/master.zip\n$ unzip master.zip && rm master.zip\n$ mv coderrect-spack-master coderrect-spack\n$ spack repo add coderrect-spack<\/pre>\n\n\n\n
$ spack install coderrect\n$ spack load coderrect<\/pre>\n\n\n\n