The Git plugin's checkout([...]) step doesn't expose http.postBuffer/ http.version tuning, which is what's reliably fixed every stuck push/clone today (VPS and both laptops) — meanwhile checkout was failing ~10 times in a row, consistently dying at 84-95% during the shallow clone (early EOF / invalid index-pack). Bypasses the plugin entirely: a plain `git clone` with those settings applied, wrapped in its own 8-attempt bash retry loop, using the existing dd13f593-06b1-4a5a-9477-2df0d186b490 credential (confirmed via credentials.xml to be a UsernamePasswordCredentialsImpl, compatible with the usernamePassword binding as-is). Code now lands in a repo/ subdirectory instead of the workspace root, so every stage referencing a repo-relative path was updated to match: - Build Docker Image: ./platform/ -> ./repo/platform/ - SonarQube Analysis: -Dsonar.sources=platform -> -Dsonar.sources=repo/platform Deploy to Kubernetes needed no changes — it only references the already-built image tag and hardcoded kubectl args, no filesystem paths into the checkout. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
103 lines
3.8 KiB
Groovy
103 lines
3.8 KiB
Groovy
pipeline {
|
|
agent {
|
|
kubernetes {
|
|
cloud 'k3s-jenkins-agents'
|
|
label 'docker-agent'
|
|
defaultContainer 'docker-cli'
|
|
}
|
|
}
|
|
|
|
options {
|
|
skipDefaultCheckout()
|
|
}
|
|
|
|
stages {
|
|
stage('Checkout') {
|
|
steps {
|
|
withCredentials([usernamePassword(
|
|
credentialsId: 'dd13f593-06b1-4a5a-9477-2df0d186b490',
|
|
usernameVariable: 'GIT_USER',
|
|
passwordVariable: 'GIT_TOKEN'
|
|
)]) {
|
|
sh '''
|
|
rm -rf repo
|
|
for i in 1 2 3 4 5 6 7 8; do
|
|
echo "Clone attempt $i..."
|
|
git -c http.postBuffer=524288000 -c http.version=HTTP/1.1 \
|
|
clone --depth 1 \
|
|
"https://$GIT_USER:$GIT_TOKEN@gitea.nav.ovh/ameniboukattaya/CloudOps.git" repo \
|
|
&& break
|
|
rm -rf repo
|
|
sleep 3
|
|
done
|
|
test -d repo/.git
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Build Docker Image') {
|
|
steps {
|
|
sh '''
|
|
docker build -t management-platform:${BUILD_NUMBER} -t management-platform:latest ./repo/platform/
|
|
echo "✅ Docker image built"
|
|
docker images management-platform:${BUILD_NUMBER} --format "Size: {{.Size}}"
|
|
'''
|
|
}
|
|
}
|
|
|
|
stage('SonarQube Analysis') {
|
|
steps {
|
|
container('sonar-scanner') {
|
|
withSonarQubeEnv('sonarqube') {
|
|
script {
|
|
def scannerHome = tool 'sonar-scanner'
|
|
sh """
|
|
${scannerHome}/bin/sonar-scanner \
|
|
-Dsonar.projectKey=management-platform \
|
|
-Dsonar.sources=repo/platform \
|
|
-Dsonar.python.version=3
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Deploy to Kubernetes') {
|
|
steps {
|
|
container('docker-cli') {
|
|
sh '''
|
|
docker save management-platform:${BUILD_NUMBER} | \
|
|
/usr/local/bin/k3s ctr -a /run/k3s/containerd/containerd.sock -n k8s.io images import -
|
|
|
|
set +x
|
|
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
|
|
CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
|
|
|
/usr/local/bin/k3s kubectl --server=https://kubernetes.default.svc \
|
|
--token="$TOKEN" --certificate-authority="$CACERT" \
|
|
set image deployment/management-platform \
|
|
management-platform=management-platform:${BUILD_NUMBER} \
|
|
-n management-platform
|
|
|
|
/usr/local/bin/k3s kubectl --server=https://kubernetes.default.svc \
|
|
--token="$TOKEN" --certificate-authority="$CACERT" \
|
|
rollout status deployment/management-platform -n management-platform --timeout=90s
|
|
|
|
echo "✅ Deployed management-platform:${BUILD_NUMBER} to Kubernetes"
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo '✅ Pipeline succeeded — build + Sonar passed, deployed to k8s'
|
|
}
|
|
failure {
|
|
echo '❌ Pipeline failed — check logs'
|
|
}
|
|
}
|
|
} |