AWS CodeBuild Integration
Integrating with AWS CodeBuild
The integration in AWS CodeBuild lets you check the code quality using Codiga as you build your software. If your code does not meet some code quality requirements, the build will fail and not ship into production.
Once you are integrated with the AWS CodeBuild, you can then add this test in a code pipeline and avoid any changes with errors to be pushed into production.
Setting up your environment
First, create an AWS CodeBuild to build your software. You need to define the following three variables in your build environment:
CODIGA_API_TOKEN
: API token you get from your tokens pageCODIGA_PROJECT_NAME
: name of the project on codiga
To define these variables, first, edit the CodeBuild configuration as shown below.
Define the environment variables, as shown below. Note that for the
CODIGA_API_TOKEN
, you need to
set the values retrieved from your profile page.
Editing your buildspec.yml
file
The next step is to edit your buildspec.yml
(or any build specification you
use for this project) in order to add commands to install and invoke
codiga-check-quality
.
- Installing the tool is done using
pip
. To install the tool, you need to usepip install codiga
- Invoking the tool
codiga-check-quality
lets you set the requirements for your code quality gate.
There is an example of how to modify your buildspec.yml
to install the tool
and check that the quality score of the project for the current commit is higher than 75.
version: 0.2
phases:
install:
commands:
- apt-get update -y
- apt-get install apt-transport-https gnupg -y
- pip install codiga
finally:
- echo Preliminary tasks done
pre_build:
commands:
- codiga-check-quality --project "${CODIGA_PROJECT_NAME}" --min-quality-score 75 --sha "${CODEBUILD_RESOLVED_SOURCE_VERSION}" --max-timeout-sec 60
finally:
- echo pre-build done
build:
commands:
- echo Entering the build phase
finally:
- echo build done
post_build:
commands:
- echo Entered the post_build phase...
- echo Build completed on `date`
Important notes:
- Invoking the tool requires that you define
CODIGA_API_TOKEN
andCODIGA_PROJECT_NAME
. Otherwise, it will not start - We analyze the revision being pushed. We use the
CODEBUILD_RESOLVED_SOURCE_VERSION
environment variable set up by CodeBuild to retrieve that information. - If the tool does not complete within 60 seconds, it fails.
Results
Once your file is committed, you can see the execution of the tool directly in the CodeBuild execution trace, as shown below. When the tool fails, it will also indicate what metrics do not meet the quality gate requirements.
Reporting an issue
You can get help by joining our Slack Community
You can report an issue directly on GitHub.
More information
The tool codiga-check-quality
is developed as an open-source tool.
You can read more and contribute to the tool on GitHub.