workflow update
CICD-UCN/Agent86/pipeline/head This commit looks good

This commit is contained in:
Karsten Jeppesen
2026-11-25 08:55:32 +01:00
parent c85ef508ec
commit 21dbe76a16
5 changed files with 63 additions and 17 deletions
+7
View File
@@ -1,6 +1,13 @@
#!/bin/bash #!/bin/bash
echo "OK" > jenkins.result echo "OK" > jenkins.result
# Check dotnet10 installed
! which dotnet || sudo apt-get install -y dotnet10
if ! which dotnet; then
echo "DOTNET NOT FOUND"
exit 1
fi
# Find all .csproj files and loop through them # Find all .csproj files and loop through them
find . -type f -name "*.csproj" | while read -r csproj; do find . -type f -name "*.csproj" | while read -r csproj; do
echo "Building $csproj..." echo "Building $csproj..."
+31 -5
View File
@@ -35,10 +35,20 @@ pipeline {
} }
stages { stages {
stage('Remove stale files') {
steps {
echo "Remove stale files"
sh "rm -f $CHANGED_FILES_FILE"
sh "rm -f $TEXT_FILES_FILE"
sh "rm -f $SCAN_JSON_FILE"
sh "rm -f $REPORT_FILE"
}
}
stage('List folder content') { stage('List folder content') {
steps { steps {
echo "List folder content" echo "List folder content"
sh "ls -l" sh "ls -la"
sh "export" sh "export"
} }
} }
@@ -46,6 +56,7 @@ pipeline {
stage('Change to unix files') { stage('Change to unix files') {
steps { steps {
echo "Change to unix files" echo "Change to unix files"
sh "! which dos2unix || sudo apt-get install -y dos2unix"
sh "/bin/dos2unix .workflow/* .workflow/*" sh "/bin/dos2unix .workflow/* .workflow/*"
sh "/bin/chmod +x .workflow/* .workflow/*" sh "/bin/chmod +x .workflow/* .workflow/*"
} }
@@ -86,7 +97,9 @@ pipeline {
} }
stage('Scan with Ollama') { stage('Scan with Ollama') {
when { expression { branch 'Security' && fileExists('text_files.txt') && sh(script: "test -s text_files.txt", returnStatus: true) == 0 } } when {
branch 'Security'
}
steps { steps {
sh ".workflow/scan_with_ollama.sh \"$TEXT_FILES_FILE\" \"$SCAN_JSON_FILE\" \"$OLLAMA_MODEL\" \"$MAX_FILE_BYTES\" \"$REQUEST_TIMEOUT_SEC\"" sh ".workflow/scan_with_ollama.sh \"$TEXT_FILES_FILE\" \"$SCAN_JSON_FILE\" \"$OLLAMA_MODEL\" \"$MAX_FILE_BYTES\" \"$REQUEST_TIMEOUT_SEC\""
archiveArtifacts artifacts: "$SCAN_JSON_FILE", allowEmptyArchive: true archiveArtifacts artifacts: "$SCAN_JSON_FILE", allowEmptyArchive: true
@@ -94,7 +107,9 @@ pipeline {
} }
stage('Build Markdown Report') { stage('Build Markdown Report') {
when { expression { branch 'Security' && fileExists('text_files.txt') && sh(script: "test -s text_files.txt", returnStatus: true) == 0 } } when {
branch 'Security'
}
steps { steps {
sh ".workflow/build_markdown_report.sh \"$SCAN_JSON_FILE\" \"$REPORT_FILE\"" sh ".workflow/build_markdown_report.sh \"$SCAN_JSON_FILE\" \"$REPORT_FILE\""
archiveArtifacts artifacts: "$REPORT_FILE", allowEmptyArchive: true archiveArtifacts artifacts: "$REPORT_FILE", allowEmptyArchive: true
@@ -102,14 +117,18 @@ pipeline {
} }
stage('Report to Gitea (Issue)') { stage('Report to Gitea (Issue)') {
when { expression { branch 'Security' && fileExists('text_files.txt') && sh(script: "test -s text_files.txt", returnStatus: true) == 0 } } when {
branch 'Security'
}
steps { steps {
sh ".workflow/create_gitea_issue.sh \"$REPORT_FILE\"" sh ".workflow/create_gitea_issue.sh \"$REPORT_FILE\""
} }
} }
stage('Quality Gate') { stage('Quality Gate') {
when { expression { branch 'Security' && fileExists('text_files.txt') && sh(script: "test -s text_files.txt", returnStatus: true) == 0 } } when {
branch 'Security'
}
steps { steps {
sh ".workflow/evaluate_threshold.sh \"$SCAN_JSON_FILE\" \"$FAIL_ON_MEDIUM_OR_HIGH\"" sh ".workflow/evaluate_threshold.sh \"$SCAN_JSON_FILE\" \"$FAIL_ON_MEDIUM_OR_HIGH\""
} }
@@ -128,6 +147,13 @@ pipeline {
post { post {
always { always {
archiveArtifacts allowEmptyArchive: true, artifacts: "${CHANGED_FILES_FILE}, ${TEXT_FILES_FILE}, ${SCAN_JSON_FILE}, ${REPORT_FILE}" archiveArtifacts allowEmptyArchive: true, artifacts: "${CHANGED_FILES_FILE}, ${TEXT_FILES_FILE}, ${SCAN_JSON_FILE}, ${REPORT_FILE}"
// Cleanup after build (if success)
cleanWs(cleanWhenNotBuilt: false,
deleteDirs: true,
disableDeferredWipeout: true,
notFailBuild: true,
patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
} }
} }
} }
+9 -3
View File
@@ -1,15 +1,21 @@
Jenkinsfile with AI provisions Jenkinsfile with AI provisions
The Build Agent should provide the following environment (in alphabetical order): The Build Agent should provide the following environment (in alphabetical order):
- GITEA_AGENT in clear text - GITEA_AGENT in clear text cicd-builder
- GITEA_API_URL in clear text - GITEA_API_URL in clear text https://gitea.a.ucnit.eu/api/v1
- GITEA_API_KEY in clear text - GITEA_API_KEY in clear text
- GIT_USER in clear text - GIT_USER in clear text
- MAX_FILE_BYTES in clear text - MAX_FILE_BYTES in clear text
- OLLAMA_API_KEY through credentials:secret text - OLLAMA_API_KEY through credentials:secret text
- OLLAMA_API_URI in clear text - OLLAMA_API_URI in clear text https://agent:12tf56so@ollama-api.a.ucnit.eu/v1
- OLLAMA_MODEL in clear text - OLLAMA_MODEL in clear text
- REQUEST_TIMEOUT_SEC through credentials:secret text - REQUEST_TIMEOUT_SEC through credentials:secret text
- FILE_EXTS in clear text (cshtml,cs,js,json) - FILE_EXTS in clear text (cshtml,cs,js,json)
And the following settings
- Remote root directory ~/jenkins
- Labels builder
- Launch method Launch agents via ssh
- Host Key Verification Strategy Not verifying
\ No newline at end of file
+2
View File
@@ -16,6 +16,8 @@ if [[ -z "$HAS_FINDINGS" ]]; then
exit 0 exit 0
fi fi
GITEA_AGENT="CICD-SYSTEM" # temporarily set this
: "${GITEA_API_URL:?Missing GITEA_API_URL}" : "${GITEA_API_URL:?Missing GITEA_API_URL}"
: "${GITEA_API_KEY:?Missing GITEA_API_KEY}" : "${GITEA_API_KEY:?Missing GITEA_API_KEY}"
: "${GITEA_AGENT:?Missing GITEA_AGENT}" : "${GITEA_AGENT:?Missing GITEA_AGENT}"
+7 -2
View File
@@ -13,8 +13,9 @@ if [[ ! -s "$FILES_LIST" ]]; then
exit 0 exit 0
fi fi
TMP_DIR="$(mktemp -d)" TMP_DIR=".workflow/scan"
trap 'rm -rf "$TMP_DIR"' EXIT [ -d $TMP_DIR ] && rm -rf $TMP_DIR
mkdir -p $TMP_DIR
SYS_PROMPT=$'You are a precise secure code scanning assistant. Analyze the provided file content and return findings as STRICT JSON only with this schema:\n{\n "findings": [\n {\n "severity": "LOW|MEDIUM|HIGH|CRITICAL",\n "rule_id": "string-identifier",\n "line": number|null,\n "description": "short human-readable description",\n "recommendation": "concise fix guidance",\n "references": ["optional references URLs or identifiers"]\n }\n ]\n}\nRules:\n- Output ONLY JSON. No markdown, no code fences, no commentary.\n- If no issues, output {\"findings\":[]}.\n- Prefer concrete, reproducible findings over theoretical. Highlight secrets, insecure configs, vulnerable patterns, risky dependencies (if visible), command injection, path traversal, deserialization, SSRF, XSS, SQLi, hardcoded credentials, bad crypto, weak TLS, etc.\n- Provide line numbers when confidently known; otherwise null.\n' SYS_PROMPT=$'You are a precise secure code scanning assistant. Analyze the provided file content and return findings as STRICT JSON only with this schema:\n{\n "findings": [\n {\n "severity": "LOW|MEDIUM|HIGH|CRITICAL",\n "rule_id": "string-identifier",\n "line": number|null,\n "description": "short human-readable description",\n "recommendation": "concise fix guidance",\n "references": ["optional references URLs or identifiers"]\n }\n ]\n}\nRules:\n- Output ONLY JSON. No markdown, no code fences, no commentary.\n- If no issues, output {\"findings\":[]}.\n- Prefer concrete, reproducible findings over theoretical. Highlight secrets, insecure configs, vulnerable patterns, risky dependencies (if visible), command injection, path traversal, deserialization, SSRF, XSS, SQLi, hardcoded credentials, bad crypto, weak TLS, etc.\n- Provide line numbers when confidently known; otherwise null.\n'
@@ -82,6 +83,10 @@ $code + "
echo "[INFO] [$idx] Scanning $file (${bytes} bytes) with model=$OLLAMA_MODEL ..." echo "[INFO] [$idx] Scanning $file (${bytes} bytes) with model=$OLLAMA_MODEL ..."
resp_json="$TMP_DIR/resp_$idx.json" resp_json="$TMP_DIR/resp_$idx.json"
set +e set +e
# HERE BE DRAGONS
echo "[DEBUG] endpoint=[${OLLAMA_API_URI%/}/chat/completions]"
echo "[DEBUG] Authorization: Bearer ${OLLAMA_API_KEY}"
http_code=$(curl -sS -w "%{http_code}" -o "$resp_json" \ http_code=$(curl -sS -w "%{http_code}" -o "$resp_json" \
--max-time "$REQUEST_TIMEOUT_SEC" --connect-timeout 10 \ --max-time "$REQUEST_TIMEOUT_SEC" --connect-timeout 10 \
-H "Authorization: Bearer ${OLLAMA_API_KEY}" \ -H "Authorization: Bearer ${OLLAMA_API_KEY}" \