Skip to content

Instantly share code, notes, and snippets.

@killertilapia
Created May 6, 2021 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save killertilapia/c9e7635807e596f20a16123ceed9c48d to your computer and use it in GitHub Desktop.
Save killertilapia/c9e7635807e596f20a16123ceed9c48d to your computer and use it in GitHub Desktop.
An example Azure YML script for running django tests in an Azure pipeline.
trigger:
batch: true
branches:
include:
- develop
jobs:
- job: 'run_tests'
pool:
vmImage: 'Ubuntu-20.04'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: 3.8
architecture: 'x64'
- task: PythonScript@0
displayName: 'Export project path'
inputs:
scriptSource: 'inline'
script: |
"""Search all subdirectories for `manage.py`."""
from glob import iglob
from os import path
# Python >= 3.5
manage_py = next(iglob(path.join('**', 'manage.py'), recursive=True), None)
if not manage_py:
raise SystemExit('Could not find a Django project')
project_location = path.dirname(path.abspath(manage_py))
print('Found Django project in', project_location)
print('##vso[task.setvariable variable=projectRoot]{}'.format(project_location))
env:
SECRET_KEY: $(secretkey)
- script: |
python -m pip install --upgrade pip pipenv setuptools wheel django
pipenv lock -r > requirements.txt
pip install -r requirements.txt
pip install unittest-xml-reporting
displayName: 'Install prerequisites'
- bash: |
export SECRET_KEY="$(secretkey)" >/dev/null 2>&1
export GLITCHTIP_DSN= "$(glitchtipdsn)" >/dev/null 2>&1
pushd '$(projectRoot)'
python manage.py test --testrunner xmlrunner.extra.djangotestrunner.XMLTestRunner --no-input --settings=settings.testing
env:
SECRET_KEY: $(secretkey)
GLITCHTIP_DSN: $(glitchtipdsn)
condition: succeededOrFailed()
displayName: 'Run tests'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFiles: "**/TEST-*.xml"
testRunTitle: 'Python $(PYTHON_VERSION)'
- job: 'build_dev_images'
dependsOn: 'run_tests'
condition: succeeded('run_tests')
pool:
vmImage: 'Ubuntu-20.04'
steps:
- template: templates/acr-login.yml
- script: |
cd nginx
docker build -t $(dockerId).azurecr.io/box_nginx:develop .
docker push $(dockerId).azurecr.io/box_nginx:develop
cd ..
docker build -t $(dockerId).azurecr.io/box_web:develop --file Dockerfile .
docker push $(dockerId).azurecr.io/box_web:develop
displayName: 'Build and push Dev Docker images to ACR'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment