Compare commits

...

23 Commits
ssss ... master

Author SHA1 Message Date
mh 24fbc1304d Update 'ttt' 4 months ago
mh 714e113a0d Update 'test1.cpp' 5 months ago
mh 0baa759bcd Update 'Jenkinsfile' 5 months ago
mh 9fbfdb27de Update 'test1.cpp' 5 months ago
mh e00ad516b0 Update 'test.txt' 5 months ago
mh 488634e59a Update 'Jenkinsfile' 5 months ago
mh 79a7128fbd Update 'Jenkinsfile' 5 months ago
mh 1923685565 Update 'ttt' 5 months ago
mh 4fbf06d6e7 this is a commit 5 months ago
mh 554a4d498c Update 'Jenkinsfile' 5 months ago
mh fd9ea41c4b Update 'Jenkinsfile' 5 months ago
mh 704aeaa91a Update 'ttt' 5 months ago
mh 92875c14ab Upload files to 'cppcheck_configs' 5 months ago
mh 61528d0031 Upload files to 'clang_configs' 5 months ago
mh d03ce5630b Upload files to '' 5 months ago
mh a866084bea Update 'test.txt' 5 months ago
mh aeddb9f3e2 Update 'test.txt' 5 months ago
mh 0151ed7213 Update 'test.txt' 5 months ago
mh a3cb58be42 Update 'test.txt' 5 months ago
mh db487d8174 Update 'test.txt' 5 months ago
mh 675fb8278d Update 'test.txt' 5 months ago
mh 24ed37f4b7 Update 'test.txt' 5 months ago
Mohammadhosain fb87b1161f Update test.txt 5 months ago
  1. 84
      Jenkinsfile
  2. 18
      clang_configs/clang_format_script.sh
  3. 18
      clang_configs/clang_tidy_script.sh
  4. 25
      cppcheck_configs/cpp_check_scripts.sh
  5. 2
      test.txt
  6. 9
      test1.cpp
  7. 1
      ttt

84
Jenkinsfile

@ -0,0 +1,84 @@
pipeline {
agent any
environment {
GITEA_CREDS = 'testtest'
GITEA_REPO_OWNER = 'mh'
GITEA_REPO_NAME = 'TEst'
GITEA_SERVER = 'http://194.5.205.38:3000'
GITEA_TOKEN = '090ac0a087634a808792833fa23368d100ec03d9'
MAIN_BRANCH = 'master'
}
stages {
stage('Clone the repo') {
steps {
echo "Clone the repo"
sh "rm -fr jenkins-test3"
git branch: "${env.MAIN_BRANCH}", credentialsId: "${env.GITEA_CREDS}", url: "${env.GITEA_SERVER}/${env.GITEA_REPO_OWNER}/${env.GITEA_REPO_NAME}.git"
}
}
stage('Code Analysis') {
parallel {
stage('CppCheck') {
steps {
sleep 3
sh 'cppcheck_configs/cpp_check_scripts.sh'
}
}
stage('Clang Tidy') {
steps {
sh 'clang_configs/clang_tidy_script.sh'
}
}
stage('Clang Format') {
steps {
sh 'clang_configs/clang_format_script.sh'
}
}
}
}
stage('Deploy') {
steps {
sleep 10
echo "Deploy"
}
}
stage('Cleaning') {
steps {
sh "rm -fr ${env.GITEA_REPO_NAME}"
}
}
}
post {
always {
script {
def status = currentBuild.result == 'SUCCESS' ? 'success' : 'failure'
def state = status == 'success' ? 'success' : 'failure'
def description = "Jenkins build ${status}"
def commitSha = env.GIT_COMMIT
def apiUrl = "${env.GITEA_SERVER}/api/v1/repos/${env.GITEA_REPO_OWNER}/${env.GITEA_REPO_NAME}/statuses/${commitSha}"
httpRequest(
url: apiUrl,
httpMode: 'POST',
customHeaders: [
[name: 'Content-Type', value: 'application/json'],
[name: 'Authorization', value: "token ${env.GITEA_TOKEN}"]
],
requestBody: """
{
"state": "${state}",
"target_url": "${env.BUILD_URL}",
"description": "${description}",
"context": "continuous-integration/jenkins"
}
"""
)
}
}
}
}

18
clang_configs/clang_format_script.sh

@ -0,0 +1,18 @@
#!/bin/bash
# Find all C++ files in the project directory and its subdirectories
files=$(find . -name "*.cpp")
# Iterate over each file
for file in $files; do
clang-format "$file" > format_errors.txt 2>&1
# Compare the original file with the formatted version
if ! cmp -s "$file" format_errors.txt; then
echo "Formatting failed for file: $file. Reasons:"
cat format_errors.txt
exit 1
fi
done
echo "Formatting successful for all files."

18
clang_configs/clang_tidy_script.sh

@ -0,0 +1,18 @@
#!/bin/bash
# Find all C++ files in the project directory and its subdirectories
files=$(find . -name "*.cpp")
for file in $files; do
echo "Running clang-tidy for file: $file"
clangTidyOutput=$(clang-tidy "$file" -- -I/usr/include/c++/11 -I/usr/include/x86_64-linux-gnu/c++/11 -DMY_DEFINES ...)
echo "$clangTidyOutput"
# Check if clang-tidy found any warnings
if [[ $clangTidyOutput == *"warning:"* ]]; then
echo "clang-tidy found warnings in file: $file"
echo "$clangTidyOutput"
exit 1
fi
done
echo "clang-tidy done successful for all files."

25
cppcheck_configs/cpp_check_scripts.sh

@ -0,0 +1,25 @@
#!/bin/bash
# Find all C++ files in the project directory and its subdirectories
files=$(find . -name "*.cpp")
# Iterate over each file
for file in $files; do
# Run cppcheck for the current file and capture its output in XML format
cppcheck --enable=all --suppress=missingIncludeSystem --xml --language=c++ -i cppcheck.xml --enable=all --inconclusive --debug --template=gcc "$file" 2>> cppcheck-result.xml
# Read the cppcheck result XML file for the current file
cppcheckOutput=$(cat cppcheck-result.xml)
# Check if cppcheck found any errors for the current file
if grep -q '<error ' cppcheck-result.xml; then
# Print cppcheck output for debugging
echo "cppcheck found errors in file: $file"
echo "$cppcheckOutput"
# Exit with non-zero status to indicate failure
exit 1
fi
done
echo "cppcheck successful. No errors found."

2
test.txt

@ -1 +1 @@
Hello World!
Hello World!@!!!aabfvv!!44

9
test1.cpp

@ -0,0 +1,9 @@
#include <stdio.h>
int main() {
int a = 5;
int b = 10;
int sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}

1
ttt

@ -1 +1,2 @@
adfdfasd
## PLEASE STAY2
Loading…
Cancel
Save