This documentation provides the steps to setup AWS CodePipeline, Azure DevOps, SonarQube and JFrog integrations.
Pre-Requisites
- Azure DevOps Repository
- Sonarqube Project
- Sonarqube Configuration
- Azure DevOps WebHooks with AWS Services
- Configure Azure DevOps Repo WebHook Trigger
- Log into the Azure Devops Portal https://dev.azure.com/
- Click
New Organizationlink to create an organization - Enter the oranization name and select
Central USfrom the list underWe'll host your projects in, and clickNext - In the
Create a project to get started', enter the project name and click+ Create Project`button. - Import the existing GitHub project into the new repo following the steps in the link
- Click the
Filesunder the repo and select thepom.xmlfile. - Click
Editbutton and add the following xml snippet to add code coverage plugin configuration after line 24 (under section)
<jacoco.version>0.8.3</jacoco.version>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>- Similarly, add the following xml configuration after the line 65 (under section) and click
Commitbutton to save the changes
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
<skip>${maven.test.skip}</skip>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
<output>file</output>
<append>true</append>
<excludes>
<exclude>*MethodAccess</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>test-compile</phase>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>- Update the following xml configuration
<artifactId>unit-testing</artifactId>with
<artifactId>spring-unit-testing-with-junit-and-mockito</artifactId>- Similarly, update the below xml configuration
<name>unit-testing</name>with
<name>spring-unit-testing-with-junit-and-mockito</name>- Click on the
User Settingsicon and selectPersonal Access Tokento create the token for AWS CodePipeline to download the repo codebase as zip file - Click
+ New Tokenbutton and provide a user-friendly name (for ex, aws-codepipeline-access-token) - Under the Scopes, select
Readunder Code section to provide read access to the token consumer. - Click
Createbutton to complete the setup.
- Go to https://sonarcloud.io
- Login using any of the GitHub, BitBucket etc credentials
- Click the
+icon in top right corner - Select
Analyse New Projectoption - Select the repo from the list and Click
Setupbutton - Under
Configuretab, select theWith Other CI Toolsoption from the Choose another analysis method options. - Select appropriate codebase
languageunder the 'What option best describes your build?' - Select the
Operation Systemname from the list under the 'What is your OS?' - Click icon next to
+and select organization name underMy Organizations - Click
Administrationand selectOrganization settings - Right corner, copy the value of the label
Key:and store it somewhere.
- Click on the
Profileicon and select theaccount name - Click on the
Securitytab - Enter a friend name for the repo access token in the
Generate Tokenfield and clickGenerate. - Copy the token string by clicking the
copybutton and save it somwhere. You cannot retrieve this again.
- Log into AWS Management Console and select
Secrets Manager - Click on the
Store a new secretbutton - Select
Other types of secretsin the Select secret type - Under the secret key/value, add the following key/value pairs
a. key: token, value: <paste the sonarqube token value from the section
SonarQube Token Setupstep 4. b. key: host, value: https://sonarcloud.io c. key: organization, value: (obtained from the section Sonarqube Project Setup step 9) - Click
Nextbutton - Enter the secret name value
dev/sonarcloudand clickNextbutton - Click
Nextbutton - Click
Storebutton to complete the setup
- Log into AWS Management Console
- Click on this link
- Click
Nextbutton - Enter the Output S3 Bucket Name as `azure-repo-codebase'
- In the Allowed IPs, enter the
Azure DevOps Services IPs for the Regional Identity Service - Central United Statesvalue 13.89.236.72,52.165.41.252,52.173.25.16,13.86.38.60,20.45.1.175,13.86.36.181,52.158.209.56 (Refer the link for different region) - In the Git Personal Access Token, paste the AzureDevOps Personal Access Token value created in the section
Azure DevOps Setupstep 11. - In the Quick Start S3 Bucket Name, enter the value
Azure-DevOps-WebHooks - In the Quick Start S3 Key Prefix, enter the value
Assets/ - Click
Next - Click
Next - In the Review screen, under Capabilities section select the checkbox for
I acknowledge that AWS CloudFormation might create IAM resources. - Click
Create stackto complete the setup - After the stack creation is completed, go to the
Outputstab and copy the value of key nameZipDownloadWebHookApi - Go to the section
Configure Azure DevOps Repo WebHook Triggerand follow the steps 1-12. - Go to
Lambdaservice and select theAzureRepo-to-Amazon-S3-ZipDlLambdalambda function to edit. - In the code editor, replace the following existing code
if 'X-Hub-Signature' in event['params']['header'].keys():
hostflavour = 'githubent'
elif 'X-Gitlab-Event' in event['params']['header'].keys():
hostflavour = 'gitlab'
elif 'User-Agent' in event['params']['header'].keys():
if event['params']['header']['User-Agent'].startswith('Bitbucket-Webhooks'):
hostflavour = 'bitbucket'
elif event['params']['header']['User-Agent'].startswith('GitHub-Hookshot'):
hostflavour = 'github'
elif 'Bitbucket-' in event['params']['header']['User-Agent']:
hostflavour = 'bitbucket-server'
elif event['body-json']['publisherId'] == 'tfs':
hostflavour='tfs'with this new code snippet
if event['body-json']['publisherId'] == 'tfs':
hostflavour='tfs'
elif 'X-Hub-Signature' in event['params']['header'].keys():
hostflavour = 'githubent'
elif 'X-Gitlab-Event' in event['params']['header'].keys():
hostflavour = 'gitlab'
elif 'User-Agent' in event['params']['header'].keys():
if event['params']['header']['User-Agent'].startswith('Bitbucket-Webhooks'):
hostflavour = 'bitbucket'
elif event['params']['header']['User-Agent'].startswith('GitHub-Hookshot'):
hostflavour = 'github'
elif 'Bitbucket-' in event['params']['header']['User-Agent']:
hostflavour = 'bitbucket-server'- Similarly, replace the following line
archive_url = event['body-json']['resourceContainers']['account']['baseUrl'] + 'DefaultCollection/' + event['body-json']['resourceContainers']['project']['id'] + '/_apis/git/repositories/' + event['body-json']['resource']['repository']['id'] + '/items'with this code
archive_url = event['body-json']['resourceContainers']['account']['baseUrl'] + event['body-json']['resourceContainers']['project']['id'] + '/_apis/git/repositories/' + event['body-json']['resource']['repository']['id'] + '/items'- Click the
Savebutton to complete the code change
- Log into the Azure DevOps portal and select the Repo
- Click the
Project Settingsbottom of the left navigatiojn - Select
service hooks - Click
+to add a new webhook - Select
Web Hooksfrom the list of Service and clickNext - Select
Code Pushedfrom the list underTrigger on this type of event - Under the
Repository, select the repo name from the list - Select
Masterfrom the list under the branch - Leave the default value
[Any]for the Pushed by member of group and clickNextbutton - In the
Actionscreen, pase the value obtained from the section Azure DevOps WebHooks with AWS Services step 14. - Click
Testbutton for test - Click
Finishbutton to complete the setup
- Log into the AWS Account and select
CodePipelineservice - Click
Create Pipelinebutton - Under the
Pipeline Settings, enter the pipeline name. - Expand the
Advanced settings - Make sure the
Default Locationoption is selected underArtifact StoreandDefault AWS Managed Keyoption under theEncryption keysection - Under the
Source, select Amazon S3 and enter the bucket nameazure-repo-codebase(specified in the step 4 under the sectionAzure DevOps WebHooks with AWS Services) and paste the S3 object key as<Azure Repo Organization Name>/<repo name>/master/<repo name>.zip - Under the
Build, selectAWS CodeBuildoption. - Click
create projectbutton (follow the steps under the sectionCodeBuild Project Setup for Unit Test) - Click the
Nextbutton - Click
skip deploy stagebutton to skip the deployment step - Review the pipeline details and click
Create Pipelinebutton to complete the initial pipeline step - Select the pipeline name link from the list
- In the pipeline screen, select
Editto add additional stages - Below Unit Test stage, click the
+ Add Stagebutton to addQuality-Gatestage - In the Add Stage, enter the stage name
Quality-Gate. - Click
+ Add action groupbutton to add the steps - Enter
code-qualityin theAction Name - Select
AWS CodeBuildin theAction provider - Select the region where the pipline s3 bucket is located
- Select
OutputArtifactfromt the list underInput Artifacts - Click
Create projectto createCodeBuild Project Setup for Quality Gate - Goto IAM service and search for the service role associated with Unit Test build project.
- Click + Add inline policy to add inline policy to give access to read the secret manager key
- Click JSON tab and paste the following json snippet:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "<secret ARN>"
}
]
}- Enter the build project name (preferrably, prefix
-unit-testwith the pipeline name) - Under
Environmentsection, selectManaged Image - Select
Ubuntufor the operation system - Select
Standardfor the runtime - Select
aws/codebuild/standard:3.0for the image. (Refer the link for which OS and image should be selected based on the lanaguge version.) - Under buildsepc, select
insert build commandsoption and clickswitch to editorlink - In the
build commandstext editor, update with the following code
version: 0.2
env:
variables:
Project: "<Sonarqube project name goes here>"
secrets-manager:
LOGIN: dev/sonarcloud:token
HOST: dev/sonarcloud:host
Organization: dev/sonarcloud:organization
phases:
install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
runtime-versions:
java: openjdk8
pre_build:
commands:
- apt-get update
- wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.3.0.2102-linux.zip
- unzip ./sonar-scanner-cli-4.3.0.2102-linux.zip
- export PATH=$PATH:/sonar-scanner-cli-4.3.0.2102-linux/bin/
build:
commands:
- mvn clean install
- mvn sonar:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization -Dsonar.jacoco.reportPath=target/coverage-reports/jacoco-unit.exec
artifacts:
files:
- '**/*'
base-directory: 'target'- Click
continue to pipelinebutton. It will take you back to the sectionCodePipeline Setupstep 21.
- Enter the build project name (pipeline name prefix with -quality-gate)
- Under
Environmentsection, selectManaged Image - Select
Ubuntufor the operation system - Select
Standardfor the runtime - Select
aws/codebuild/standard:4.0for the image. (Refer the link for which OS and image should be selected based on the lanaguge version.) - Under buildsepc, select
insert build commandsoption and clickswitch to editorlink - In the
build commandstext editor, update with the following code and update the Project variable with the sonarqube project name
version: 0.2
env:
variables:
Project: "<Sonarqube project name goes here>"
phases:
install:
#If you use the Ubuntu standard image 2.0 or later, you must specify runtime-versions.
#If you specify runtime-versions and use an image other than Ubuntu standard image 2.0, the build fails.
runtime-versions:
java: corretto8
build:
commands:
- curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=$Project >result.json
- if [ $(jq -r '.projectStatus.status' result.json) = ERROR ] ; then $CODEBUILD_BUILD_SUCCEEDING -eq 0 ;fi
- Click
continue to pipelinebutton. It will take you back to the sectionCodePipeline Setupstep 8.
- Log into the Azure DevOps portal and select the Repo
- Select any file (for ex, readme.md) and click
Editbutton - Make some changes (doesn't matter what change it is)
- Click
Savebutton - Click
Commitbutton in the commit dialog screen to trigger the pipeline - Goto AWS CodePipeline and select the pipeline name
- Check for the build is triggered
- Log into the AWS Account and select the Region where the AWS CodePipeline project will be created.
- Goto AWS Marketplace and click Discover products
- Search for 'JFrog Open Source' and select it from the list
- Click
continue to subscribebutton - Click
continue to configurationbutton - Leave the default selection under
Delivery MethodandSoftware Version - Select the desired
regionfrom the list and clickContineu to Launchbutton.