-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Sonarqube polling script update (#2846)
* added migration for sonarqube plugin with polling feature * updated plugin_pipeline script for legacy support * update migration script for polling script * updated if condition in sonar plugin script
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
DELETE FROM plugin_step_variable WHERE name = 'UsePropertiesFileFromProject'; | ||
|
||
DELETE FROM plugin_step_variable WHERE name = 'CheckForSonarAnalysisReport'; | ||
|
||
DELETE FROM plugin_step_variable WHERE name = 'AbortPipelineOnPolicyCheckFailed'; | ||
|
||
UPDATE plugin_pipeline_script SET script=E'PathToCodeDir=/devtroncd$CheckoutPath | ||
cd $PathToCodeDir | ||
echo "sonar.projectKey=$SonarqubeProjectKey" > sonar-project.properties | ||
docker run | ||
--rm | ||
-e SONAR_HOST_URL=$SonarqubeEndpoint | ||
-e SONAR_LOGIN=$SonarqubeApiKey | ||
-v "/$PWD:/usr/src" | ||
sonarsource/sonar-scanner-cli' WHERE id = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
do $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT * FROM plugin_step_variable WHERE name = 'UsePropertiesFileFromProject' AND plugin_step_id = 2) THEN | ||
INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by) | ||
VALUES(nextval('id_seq_plugin_step_variable'),2,'UsePropertiesFileFromProject','BOOL','Boolean value - true or false. Whether poll Generated Report or not','t','f',false,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1); | ||
END IF; | ||
END; | ||
$$; | ||
|
||
INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by) | ||
VALUES(nextval('id_seq_plugin_step_variable'),2,'CheckForSonarAnalysisReport','BOOL','Boolean value - true or false. Whether poll Generated Report or not','t','f',false,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1); | ||
|
||
INSERT INTO plugin_step_variable (id,plugin_step_id,name,format,description,is_exposed,allow_empty_value,default_value,value,variable_type,value_type,previous_step_index,variable_step_index,variable_step_index_in_plugin,reference_variable_name,deleted,created_on,created_by,updated_on,updated_by) | ||
VALUES(nextval('id_seq_plugin_step_variable'),2,'AbortPipelineOnPolicyCheckFailed','BOOL','Boolean value - true or false. Whether to proceed on policy check failed or not','t','f',false,null,'INPUT','NEW',null,1,null,null,'f','now()',1,'now()',1); | ||
|
||
|
||
UPDATE plugin_pipeline_script SET script=E'PathToCodeDir=/devtroncd$CheckoutPath | ||
cd $PathToCodeDir | ||
if [[ -z "$UsePropertiesFileFromProject" ]] | ||
then | ||
echo "sonar.projectKey=$SonarqubeProjectKey" > sonar-project.properties | ||
docker run \\ | ||
--rm \\ | ||
-e SONAR_HOST_URL=$SonarqubeEndpoint \\ | ||
-e SONAR_LOGIN=$SonarqubeApiKey \\ | ||
-v "/$PWD:/usr/src" \\ | ||
sonarsource/sonar-scanner-cli | ||
elif [[ $UsePropertiesFileFromProject == false ]] | ||
then | ||
echo "sonar.projectKey=$SonarqubeProjectKey" > sonar-project.properties | ||
docker run \\ | ||
--rm \\ | ||
-e SONAR_HOST_URL=$SonarqubeEndpoint \\ | ||
-e SONAR_LOGIN=$SonarqubeApiKey \\ | ||
-v "/$PWD:/usr/src" \\ | ||
sonarsource/sonar-scanner-cli | ||
if [[ $CheckForSonarAnalysisReport == true && ! -z "$CheckForSonarAnalysisReport" ]] | ||
then | ||
status=$(curl -u ${SonarqubeApiKey}: -sS ${SonarqubeEndpoint}/api/qualitygates/project_status?projectKey=${SonarqubeProjectKey}&branch=master) | ||
project_status=$(echo $status | jq -r ".projectStatus.status") | ||
echo "********* SonarQube Policy Report *********" | ||
echo $status | ||
if [[ $AbortPipelineOnPolicyCheckFailed == true && $project_status == "ERROR" ]] | ||
then | ||
echo "********* SonarQube Policy Violated *********" | ||
echo "********* Exiting Build *********" | ||
exit | ||
elif [[ $AbortPipelineOnPolicyCheckFailed == true && $project_status == "OK" ]] | ||
then | ||
echo "********* SonarQube Policy Passed *********" | ||
fi | ||
fi | ||
fi' WHERE id=2; |