Files
DevOpsLab/cicd/azure-devops/azure-pipelines.yml
Сергей Антропов d37f59ba77
Some checks failed
Ansible Testing / lint (push) Has been cancelled
Ansible Testing / test (default) (push) Has been cancelled
Ansible Testing / test (minimal) (push) Has been cancelled
Ansible Testing / test (performance) (push) Has been cancelled
Ansible Testing / deploy-check (push) Has been cancelled
Переименование проекта AnsibleLab в DevOpsLab
2025-10-27 10:46:04 +03:00

168 lines
4.5 KiB
YAML
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.

# Azure DevOps Pipeline для DevOpsLab
# Автор: Сергей Антропов
# Сайт: https://devops.org.ru
trigger:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
variables:
ANSIBLE_FORCE_COLOR: 'true'
DOCKER_TLS_CERTDIR: ''
stages:
# Стадия 1: Lint проверка
- stage: Lint
displayName: '🔍 Lint Check'
jobs:
- job: LintJob
displayName: 'Run Lint'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'Use Python 3.11'
- script: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
displayName: 'Install Dependencies'
- script: |
echo "🔍 Проверка синтаксиса ролей..."
make role lint
displayName: 'Run Ansible Lint'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '.ansible-lint'
artifactName: 'lint-results'
condition: always()
# Стадия 2: Тестирование
- stage: Test
displayName: '🧪 Role Testing'
dependsOn: Lint
condition: succeeded()
jobs:
- job: TestJob
displayName: 'Run Tests'
strategy:
matrix:
minimal:
preset: minimal
default:
preset: default
performance:
preset: performance
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'Use Python 3.11'
- script: |
sudo apt-get update
sudo apt-get install -y docker.io make
sudo systemctl start docker
sudo usermod -aG docker $USER
displayName: 'Install System Dependencies'
- script: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
displayName: 'Install Python Dependencies'
- script: |
make docker setup-builder
make docker build
displayName: 'Setup Docker and Build Images'
- script: |
echo "🧪 Тестирование с preset: $(preset)"
make role test $(preset)
displayName: 'Run Molecule Tests'
env:
PRESET: $(preset)
- task: PublishTestResults@2
inputs:
testResultsFiles: 'molecule/default/.molecule/reports/junit.xml'
testRunTitle: 'Molecule Test Results - $(preset)'
condition: always()
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: 'molecule/default/.molecule'
artifactName: 'test-results-$(preset)'
condition: always()
# Стадия 3: Деплой (только для main ветки)
- stage: Deploy
displayName: '🚀 Deploy Check'
dependsOn: [Lint, Test]
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
jobs:
- job: DeployJob
displayName: 'Check Deployment'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'Use Python 3.11'
- script: |
pip install --upgrade pip
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml
displayName: 'Install Dependencies'
- script: |
mkdir -p inventory
cat > inventory/hosts.ini << EOF
[test_servers]
localhost ansible_connection=local
[all:vars]
ansible_python_interpreter=python3
EOF
displayName: 'Create Inventory File'
- script: |
echo "🚀 Проверка развертывания (dry-run)..."
make role deploy
displayName: 'Run Deployment Check'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: 'deployment.log'
artifactName: 'deployment-results'
condition: always()
# Уведомления
- stage: Notify
displayName: '📢 Notifications'
dependsOn: [Lint, Test, Deploy]
condition: always()
jobs:
- job: NotifyJob
displayName: 'Send Notifications'
steps:
- script: |
echo "🔍 Lint: $(Lint.result)"
echo "🧪 Test: $(Test.result)"
echo "🚀 Deploy: $(Deploy.result)"
if [ "$(Lint.result)" = "Succeeded" ] && [ "$(Test.result)" = "Succeeded" ]; then
echo "✅ Все проверки пройдены успешно!"
else
echo "❌ Проверки не пройдены!"
exit 1
fi
displayName: 'Check Results and Notify'