Files
DevOpsLab/cicd/jenkins/Jenkinsfile
Сергей Антропов 787ab06e25 feat: Добавлены 3 стадии в CI/CD пайплайны (lint, test, deploy)
- GitHub Actions: добавлены стадии lint, test, deploy с зависимостями
- Azure DevOps: добавлены стадии lint, test, deploy с зависимостями
- Jenkins: добавлены стадии lint, test, deploy с зависимостями
- GitLab CI: создан новый .gitlab-ci.yml с 3 стадиями

Особенности:
- Деплой происходит только после успешного прохождения lint и test
- Деплой выполняется только для main ветки
- Добавлены уведомления о результатах
- Используются make команды для консистентности
- Параллельное тестирование с разными preset'ами
2025-10-25 19:33:37 +03:00

139 lines
4.7 KiB
Groovy
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Jenkins Pipeline для AnsibleLab
// Автор: Сергей Антропов
// Сайт: https://devops.org.ru
pipeline {
agent any
environment {
ANSIBLE_FORCE_COLOR = 'true'
DOCKER_TLS_CERTDIR = ''
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
// Стадия 1: Lint проверка
stage('🔍 Lint Check') {
steps {
sh '''
echo "🔍 Проверка синтаксиса ролей..."
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
make role lint
'''
}
post {
always {
archiveArtifacts artifacts: '.ansible-lint', allowEmptyArchive: true
}
}
}
// Стадия 2: Тестирование
stage('🧪 Role Testing') {
parallel {
stage('Test Minimal') {
steps {
sh '''
echo "🧪 Тестирование с preset: minimal"
sudo apt-get update
sudo apt-get install -y docker.io make
sudo systemctl start docker
sudo usermod -aG docker $USER
make docker setup-builder
make docker build
make role test minimal
'''
}
}
stage('Test Default') {
steps {
sh '''
echo "🧪 Тестирование с preset: default"
sudo apt-get update
sudo apt-get install -y docker.io make
sudo systemctl start docker
sudo usermod -aG docker $USER
make docker setup-builder
make docker build
make role test default
'''
}
}
stage('Test Performance') {
steps {
sh '''
echo "🧪 Тестирование с preset: performance"
sudo apt-get update
sudo apt-get install -y docker.io make
sudo systemctl start docker
sudo usermod -aG docker $USER
make docker setup-builder
make docker build
make role test performance
'''
}
}
}
}
// Стадия 3: Деплой (только для main ветки)
stage('🚀 Deploy Check') {
when {
branch 'main'
}
steps {
sh '''
echo "🚀 Проверка развертывания (dry-run)..."
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
mkdir -p inventory
cat > inventory/hosts.ini << EOF
[test_servers]
localhost ansible_connection=local
[all:vars]
ansible_python_interpreter=python3
EOF
make role deploy
'''
}
post {
always {
archiveArtifacts artifacts: 'deployment.log', allowEmptyArchive: true
}
}
}
}
post {
always {
archiveArtifacts artifacts: 'molecule/default/.molecule/**/*', allowEmptyArchive: true
publishTestResults testResultsPattern: 'molecule/default/.molecule/reports/junit.xml'
}
success {
echo '✅ Все проверки пройдены успешно!'
echo '🔍 Lint: Success'
echo '🧪 Test: Success'
echo '🚀 Deploy: Success'
}
failure {
echo '❌ Проверки не пройдены!'
echo '🔍 Lint: Failed'
echo '🧪 Test: Failed'
echo '🚀 Deploy: Failed'
}
}
}