Fetch Sonar Quality gate status using api in Azure DevOps pipelines - api

We have a shell script in submodules which will be called in our Azure pipelines yaml file to fetch the status of the Sonar quality gate using api.
But we are facing issue, its printing the status but along with that some line no error we are getting for if condition.
echo "Fetching the Sonar Quality gate status using api"
quality_gatesstatus=$(curl -u $sonar_token:
https://$sonar_server/api/qualitygates/project_status?projectKey=$SONAR_PROJECT_KEY&pullRequest=$PullRequestId | grep -Po '"status": *\K"[^"]*"')
echo $PullRequestId
echo "Checking the Quality gate status"
if ($quality_gatesstatus != "OK") && ($quality_gatesstatus != "NONE")
then
echo "Check Sonar server and fix the issues"
echo $quality_gatesstatus
exit 1
else
echo "No code violations found"
exit 0
fi
Error logs: Checking the Quality gate status
ci/forest/dotnetcore/bin/sonar-quality-gates-checker.sh: line 23: {"projectStatus":{"status":"OK","conditions":[{"status":"OK","metricKey":"new_reliability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"reliability_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_security_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"security_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_maintainability_rating","comparator":"GT","periodIndex":1,"errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"sqale_rating","comparator":"GT","errorThreshold":"1","actualValue":"1"},{"status":"OK","metricKey":"new_coverage","comparator":"LT","periodIndex":1,"errorThreshold":"80","actualValue":"100.0"},{"status":"OK","metricKey":"coverage","comparator":"LT","errorThreshold":"80","actualValue":"93.5"},{"status":"OK","metricKey":"new_duplicated_lines_density","comparator":"GT","periodIndex":1,"errorThreshold":"3","actualValue":"0.0"},{"status":"OK","metricKey":"duplicated_lines_density","comparator":"GT","errorThreshold":"3","actualValue":"0.0"},{"status":"OK","metricKey":"new_blocker_violations","comparator":"GT","periodIndex":1,"errorThreshold":"0","actualValue":"0"}],"periods":[{"index":1,"mode":"PREVIOUS_VERSION","date":"2020-09-28T09:09:08+0200"}],"ignoredConditions":false,"period":{"mode":"PREVIOUS_VERSION","date":"2020-09-28T09:09:08+0200"}}}: command not found
No code violations found
You can see the status is all OK but still its giving some line number 23 and I feel by default it is going to the "No code violations found" message from IF condition. So please help us to resolve where we are making mistake.

Related

sudo and permission issues getting me crazy

I have defined a bash script to prepare gpio27 for setting it to 0 or 1 through additional scripts on a RaspberryPi Zero 2 with Buster installed.
The script is the following one:
#!/bin/bash
echo "27" > /sys/class/gpio/export
echo "out" > /sys/class/gpio/gpio27/direction
1- If I run this script as user "pi", I get a permission denied error (NOK):
/home/pi/bin/prep27: line 3: /sys/class/gpio/gpio27/direction: Permision denied
2- If I run the conflictive line ‘echo "out" > /sys/class/gpio/gpio27/direction’ as user pi (no sudo), I get no error (OK):
echo "out" > /sys/class/gpio/gpio27/direction
3- if I replace in the script the third line by ‘sudo echo "out" > /sys/class/gpio/gpio27/direction’ and I execute the script as pi, I also get a permission denied error (NOK):
#!/bin/bash
echo "27" > /sys/class/gpio/export
sudo echo "out" > /sys/class/gpio/gpio27/direction
4- if i sudo execute the script as user pi, I get no error (OK)
sudo /home/pi/bin/prep27
Could you help me understand these permission issues with the script and its contents ?
Thanks very much
I believe the problem you're facing has to do with the way the Raspi is allocating permissions after you've created the pin. That works using a mechanism called udev that changes the permissions on the new "file" /sys/class/gpio/gpio27/direction after it is created by the previous export line. The problem now is, that this requires a bit of time to work correctly.
To work around this, you have to add a delay after the echo "27" > /sys/class/gpio/export line (1 second or so should do). Alternatively, you can repeat the direction line until it works.

How to view detailed error message in failed build

So this is the only thing I see on failed build. When running npm scripts on a cli, you usually see more than the exit status. Is there some option to view the entire cli output instead of this pseudo log?
I contacted support and was told to cat the debug log in order to see the output.
#!/bin/bash
set -ex
cat $(find $HOME/.npm/_logs -name '*-debug.log')

Metasploitable 3 - System error 67

I am trying to set up Metasploitable 3 (VirtualBox) on my Ubuntu 16.04.
I have done everything according to the guidelines of the inventors (https://github.com/rapid7/metasploitable3) when it comes to dependencies etc.
However, when I'm trying to start it (via vagrant up --provision win2k8) I get this nasty little error, that I just can't fix.
It always says:
win2k8: System error 67 has occurred.
win2k8: The network name cannot be found.
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
cmd /q /c "c:\tmp\vagrant-shell.bat"
Stdout from the command:
CMDKEY: Credential added successfully.
Stderr from the command:
System error 67 has occurred.
The network name cannot be found.
I just can't find anything out on the internet. I only "know" it has something to do with network settings. But I don't know what to do now.
I'd appreciate some help!

How to fail gitlab CI build?

I am trying to fail a build in gitlab CI and get email notification about it.
My build script is this:
echo "Listing files!"
ls -la
echo "##########################Preparing build##########################"
mkdir build
cd build
echo "Generating make files"
cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_VERBOSE_MAKEFILE=on ..
echo "##########################Building##########################"
make
I have commited the code that breaks build. However, instead of finishing, build seems to be stuck in "running" state after exiting make. Last line is:
make: *** [all] Error 2
I also get no notifications.
How can i diagnose what is happening?
Upd.: in runner, following is repeated in log:
Submitting build <..> to coordinator...response error: 500
In production.log and sideq.log of gitlab_ci, following is written:
ERROR: Error connecting to Redis on localhost:6379 (ECONNREFUSED)
Full message with stacktrace is here: pastebin.
I have the same problem, i can help you with a workaround but im trying to fully fix it.
1- most of the times he hangs but the jobs keeps on going and actually finishes it, you can see the processes inside the machine, example: in my case it compiles and in the end it uses docker to publish the build, so the process docker doesn't exist until he reaches that phase.
2- to workaround this issue you have to make the data persistent and "retry" the download over and over again until he downloads everything he needs.
PS: stating what kind of OS you are using always helps.

Monit errors when running "check program" for custom script

I am getting syntax errors when I try to check the exit status of a bash script using monit's "check program". If I run the bash script manually, it doesn't error. But if I do monit reload with my monit check program in the config, monit gives me errors.
Here's my current monit .conf file --
check program myscript with path "/etc/monit.d/script_to_run.sh"
if status != 0 then alert
If I change it to this to make sure monit uses bash to parse the file...
check program myscript with path "/usr/bash /etc/monit.d/script_to_run.sh"
if status != 0 then alert
Then I get this error
Warning: Program does not exist: '"/bin/bash /etc/monit.d/script_to_run.sh"'
Even a test script results in errors --
If I have this in script_to_run.sh:
#!/bin/bash
exit 0
Monit will complain
Error: syntax error 'exit'
If I have this in script_to_run.sh:
#!/bin/bash
echo "hello"
Monit will complain
Error: syntax error 'echo'
For reference -- I have monit 5.4, have followed the "check program" example in the man monit doc, and am able to configure/use monit "check process..." just fine on the same server.
ok, fixed. for future reference for anyone reading this -- never put .sh files in /etc/monit.d/
that was the problem. i moved the .sh file to a different directory and everything is fine now.
I am using Amazon AMI on AWS cloud. Unfortunately, by default Amazon is shipping older version of Monit - 5.2.5
https://forums.aws.amazon.com/thread.jspa?threadID=215645
They suggest to install version of monit otherwise. Amazon forum gave this workaround:
sudo yum install -y https://kojipkgs.fedoraproject.org//packages/monit/5.14/1.el6/x86_64/monit-5.14-1.el6.x86_64.rpm