64 lines
2.3 KiB
Groovy
64 lines
2.3 KiB
Groovy
pipeline {
|
|
agent {
|
|
label 'jnlp'
|
|
}
|
|
|
|
environment {
|
|
ACR_USERNAME = 'marcin00'
|
|
ACR_PASSWORD = credentials('acr-password-secret-id')
|
|
DOCKER_REGISTRY_URL = 'marcin00.azurecr.io'
|
|
DOCKER_IMAGE = "${DOCKER_REGISTRY_URL}/user-microservice:${GIT_COMMIT}"
|
|
}
|
|
|
|
stages {
|
|
stage('Code Tests') {
|
|
steps {
|
|
container('python') {
|
|
dir('api') {
|
|
sh '''
|
|
python3 -m venv env
|
|
source env/bin/activate
|
|
pip install -r requirements.txt pytest
|
|
python3 -m pytest --junit-xml=pytest_junit.xml
|
|
'''
|
|
}
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
junit testResults: '**/*pytest_junit.xml'
|
|
}
|
|
}
|
|
}
|
|
|
|
stage('Build & Push Docker') {
|
|
steps {
|
|
container('docker') {
|
|
sh label: 'Build Docker image', script: 'docker build -t ${DOCKER_IMAGE} .'
|
|
|
|
sh label: 'Install bash', script: 'apk add --no-cache bash'
|
|
|
|
sh label: 'Install dgoss', script: '''
|
|
wget https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -O goss
|
|
wget https://github.com/aelsabbahy/goss/releases/latest/download/dgoss -O dgoss
|
|
chmod +rx *goss
|
|
'''
|
|
|
|
withEnv(['GOSS_OPTS=-f junit', 'GOSS_PATH=./goss', 'GOSS_SLEEP=3', 'SQLALCHEMY_DATABASE_URI=sqlite:///:memory:']) {
|
|
sh label: 'run image tests', script: './dgoss run -e SQLALCHEMY_DATABASE_URI=sqlite:///:memory: ${DOCKER_IMAGE} > goss_junit.xml'
|
|
}
|
|
sh '''
|
|
echo "${ACR_PASSWORD}" | docker login marcin00.azurecr.io -u $ACR_USERNAME --password-stdin
|
|
docker push ${DOCKER_IMAGE}
|
|
'''
|
|
}
|
|
}
|
|
post {
|
|
always {
|
|
junit testResults: '**/*goss_junit.xml'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|