refactor: Update descriptions and messages in Jenkins pipeline scripts for clarity
This commit is contained in:
@@ -5,17 +5,17 @@ pipeline {
|
|||||||
string(
|
string(
|
||||||
name: 'REPO_URL',
|
name: 'REPO_URL',
|
||||||
defaultValue: 'https://git.crowmate.fr/crowmate/Nest.git',
|
defaultValue: 'https://git.crowmate.fr/crowmate/Nest.git',
|
||||||
description: 'URL du repo Gitea à cloner'
|
description: 'Gitea repository URL to clone'
|
||||||
)
|
)
|
||||||
string(
|
string(
|
||||||
name: 'BRANCH',
|
name: 'BRANCH',
|
||||||
defaultValue: 'main',
|
defaultValue: 'main',
|
||||||
description: 'Branche à builder'
|
description: 'Branch to build'
|
||||||
)
|
)
|
||||||
string(
|
string(
|
||||||
name: 'IMAGE_TAG',
|
name: 'IMAGE_TAG',
|
||||||
defaultValue: 'latest',
|
defaultValue: 'latest',
|
||||||
description: 'Tag des images Docker (ex: latest, v1.0.0)'
|
description: 'Docker image tag (e.g. latest, v1.0.0)'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ pipeline {
|
|||||||
credentialsId: env.GITEA_CREDENTIALS_ID
|
credentialsId: env.GITEA_CREDENTIALS_ID
|
||||||
]]
|
]]
|
||||||
])
|
])
|
||||||
echo "✅ Repo cloné"
|
echo "Repository cloned"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,28 +51,28 @@ pipeline {
|
|||||||
)]) {
|
)]) {
|
||||||
sh '''
|
sh '''
|
||||||
echo "$REGISTRY_PASS" | docker login ''' + env.REGISTRY + ''' -u "$REGISTRY_USER" --password-stdin
|
echo "$REGISTRY_PASS" | docker login ''' + env.REGISTRY + ''' -u "$REGISTRY_USER" --password-stdin
|
||||||
echo "✅ Connecté au registry Gitea"
|
echo "Connected to Gitea registry"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
echo "🔨 Build nest-api..."
|
echo "Build nest-api..."
|
||||||
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG} ./nest-backend
|
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG} ./nest-backend
|
||||||
|
|
||||||
echo "🔨 Build nest-front..."
|
echo "Build nest-front..."
|
||||||
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG} ./nest-front
|
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG} ./nest-front
|
||||||
|
|
||||||
echo "🔨 Build nest-intra..."
|
echo "Build nest-intra..."
|
||||||
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-intra:${params.IMAGE_TAG} ./nest-intra
|
docker build -t ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-intra:${params.IMAGE_TAG} ./nest-intra
|
||||||
"""
|
"""
|
||||||
|
|
||||||
sh """
|
sh """
|
||||||
echo "📤 Push nest-api..."
|
echo "Push nest-api..."
|
||||||
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG}
|
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG}
|
||||||
|
|
||||||
echo "📤 Push nest-front..."
|
echo "Push nest-front..."
|
||||||
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG}
|
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG}
|
||||||
|
|
||||||
echo "📤 Push nest-intra..."
|
echo "Push nest-intra..."
|
||||||
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-intra:${params.IMAGE_TAG}
|
docker push ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-intra:${params.IMAGE_TAG}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -85,13 +85,13 @@ pipeline {
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "🎉 Images buildées et pushées avec succès (tag: ${params.IMAGE_TAG})"
|
echo "Images built and pushed successfully (tag: ${params.IMAGE_TAG})"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "💥 Échec du build/push"
|
echo "Build/push failed"
|
||||||
}
|
}
|
||||||
always {
|
always {
|
||||||
// Nettoyage des images locales pour ne pas saturer le disque
|
// Clean local images to avoid filling up disk space
|
||||||
sh """
|
sh """
|
||||||
docker rmi ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG} || true
|
docker rmi ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-api:${params.IMAGE_TAG} || true
|
||||||
docker rmi ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG} || true
|
docker rmi ${env.REGISTRY}/${env.REGISTRY_OWNER}/nest-front:${params.IMAGE_TAG} || true
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ pipeline {
|
|||||||
string(
|
string(
|
||||||
name: 'REPO_URL',
|
name: 'REPO_URL',
|
||||||
defaultValue: 'https://git.crowmate.fr/crowmate/Nest.git',
|
defaultValue: 'https://git.crowmate.fr/crowmate/Nest.git',
|
||||||
description: 'URL du repo Gitea (pour récupérer le docker-compose.prod.yml)'
|
description: 'Gitea repository URL (to retrieve docker-compose.prod.yml)'
|
||||||
)
|
)
|
||||||
string(
|
string(
|
||||||
name: 'BRANCH',
|
name: 'BRANCH',
|
||||||
defaultValue: 'main',
|
defaultValue: 'main',
|
||||||
description: 'Branche'
|
description: 'Branch'
|
||||||
)
|
)
|
||||||
string(
|
string(
|
||||||
name: 'STACK_NAME',
|
name: 'STACK_NAME',
|
||||||
defaultValue: 'nest',
|
defaultValue: 'nest',
|
||||||
description: 'Nom de la stack dans Portainer'
|
description: 'Stack name in Portainer'
|
||||||
)
|
)
|
||||||
string(
|
string(
|
||||||
name: 'IMAGE_TAG',
|
name: 'IMAGE_TAG',
|
||||||
defaultValue: 'latest',
|
defaultValue: 'latest',
|
||||||
description: 'Tag des images à déployer'
|
description: 'Image tag to deploy'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ pipeline {
|
|||||||
credentialsId: env.GITEA_CREDENTIALS_ID
|
credentialsId: env.GITEA_CREDENTIALS_ID
|
||||||
]]
|
]]
|
||||||
])
|
])
|
||||||
echo "✅ Repo cloné"
|
echo "Repository cloned"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,47 +51,47 @@ pipeline {
|
|||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
if (!fileExists('docker-compose.prod.yml')) {
|
if (!fileExists('docker-compose.prod.yml')) {
|
||||||
error("❌ docker-compose.prod.yml introuvable à la racine du repo !")
|
error("docker-compose.prod.yml not found at the repository root")
|
||||||
}
|
}
|
||||||
echo "✅ docker-compose.prod.yml trouvé"
|
echo "docker-compose.prod.yml found"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy sur Portainer') {
|
stage('Deploy to Portainer') {
|
||||||
steps {
|
steps {
|
||||||
withCredentials([string(credentialsId: 'portainer-token', variable: 'PORTAINER_TOKEN')]) {
|
withCredentials([string(credentialsId: 'portainer-token', variable: 'PORTAINER_TOKEN')]) {
|
||||||
sh '''
|
sh '''
|
||||||
COMPOSE_CONTENT=$(base64 -w 0 docker-compose.prod.yml)
|
COMPOSE_CONTENT=$(base64 -w 0 docker-compose.prod.yml)
|
||||||
|
|
||||||
# Récupère la liste des stacks
|
# Get the list of stacks
|
||||||
STACKS=$(curl -s -X GET "''' + env.PORTAINER_URL + '''/api/stacks" \
|
STACKS=$(curl -s -X GET "''' + env.PORTAINER_URL + '''/api/stacks" \
|
||||||
-H "X-API-Key: $PORTAINER_TOKEN")
|
-H "X-API-Key: $PORTAINER_TOKEN")
|
||||||
|
|
||||||
# Cherche si la stack existe déjà
|
# Check whether the stack already exists
|
||||||
STACK_ID=$(echo "$STACKS" | jq -r '.[] | select(.Name == "''' + params.STACK_NAME + '''") | .Id')
|
STACK_ID=$(echo "$STACKS" | jq -r '.[] | select(.Name == "''' + params.STACK_NAME + '''") | .Id')
|
||||||
|
|
||||||
if [ -n "$STACK_ID" ]; then
|
if [ -n "$STACK_ID" ]; then
|
||||||
echo "🔄 Stack existante (ID: $STACK_ID), mise à jour..."
|
echo "Existing stack found (ID: $STACK_ID), updating..."
|
||||||
RESPONSE=$(curl -s -X PUT "''' + env.PORTAINER_URL + '''/api/stacks/$STACK_ID?endpointId=''' + env.PORTAINER_ENV_ID + '''" \
|
RESPONSE=$(curl -s -X PUT "''' + env.PORTAINER_URL + '''/api/stacks/$STACK_ID?endpointId=''' + env.PORTAINER_ENV_ID + '''" \
|
||||||
-H "X-API-Key: $PORTAINER_TOKEN" \
|
-H "X-API-Key: $PORTAINER_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"stackFileContent\": \"$COMPOSE_CONTENT\", \"prune\": true, \"pullImage\": true}")
|
-d "{\"stackFileContent\": \"$COMPOSE_CONTENT\", \"prune\": true, \"pullImage\": true}")
|
||||||
else
|
else
|
||||||
echo "🚀 Création de la stack ''' + params.STACK_NAME + '''..."
|
echo "Creating stack ''' + params.STACK_NAME + '''..."
|
||||||
RESPONSE=$(curl -s -X POST "''' + env.PORTAINER_URL + '''/api/stacks/create/standalone/string?endpointId=''' + env.PORTAINER_ENV_ID + '''" \
|
RESPONSE=$(curl -s -X POST "''' + env.PORTAINER_URL + '''/api/stacks/create/standalone/string?endpointId=''' + env.PORTAINER_ENV_ID + '''" \
|
||||||
-H "X-API-Key: $PORTAINER_TOKEN" \
|
-H "X-API-Key: $PORTAINER_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"name\": \"''' + params.STACK_NAME + '''\", \"stackFileContent\": \"$COMPOSE_CONTENT\"}")
|
-d "{\"name\": \"''' + params.STACK_NAME + '''\", \"stackFileContent\": \"$COMPOSE_CONTENT\"}")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Vérifie si la réponse contient une erreur
|
# Check whether the response contains an error
|
||||||
if echo "$RESPONSE" | jq -e '.message' > /dev/null 2>&1; then
|
if echo "$RESPONSE" | jq -e '.message' > /dev/null 2>&1; then
|
||||||
echo "❌ Erreur Portainer : $(echo $RESPONSE | jq -r '.message')"
|
echo "Portainer error: $(echo $RESPONSE | jq -r '.message')"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ Stack déployée avec succès !"
|
echo "Stack deployed successfully"
|
||||||
'''
|
'''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,10 +101,10 @@ pipeline {
|
|||||||
|
|
||||||
post {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "🎉 Stack '${params.STACK_NAME}' déployée sur Portainer (tag: ${params.IMAGE_TAG})"
|
echo "Stack '${params.STACK_NAME}' deployed to Portainer (tag: ${params.IMAGE_TAG})"
|
||||||
}
|
}
|
||||||
failure {
|
failure {
|
||||||
echo "💥 Échec du déploiement de la stack '${params.STACK_NAME}'"
|
echo "Failed to deploy stack '${params.STACK_NAME}'"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user