Updated Jenkins pipeline to use in Kubernetes
This commit is contained in:
parent
76a351710f
commit
8887f1b2bd
43
Jenkinsfile
vendored
43
Jenkinsfile
vendored
@ -1,21 +1,22 @@
|
||||
pipeline {
|
||||
agent any
|
||||
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}"
|
||||
ACR_NAME = 'marcin00'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
stage('Code Tests') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
stage('Test python app') {
|
||||
steps {
|
||||
script {
|
||||
container('python') {
|
||||
dir('api') {
|
||||
sh '''
|
||||
cd api
|
||||
python3 -m venv env
|
||||
source env/bin/activate
|
||||
pip install -r requirements.txt pytest
|
||||
@ -30,10 +31,11 @@ pipeline {
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Build & test docker image') {
|
||||
|
||||
stage('Build & Push Docker') {
|
||||
steps {
|
||||
script {
|
||||
appImage = docker.build("${DOCKER_IMAGE}")
|
||||
container('docker') {
|
||||
sh label: 'Build Docker image', script: 'docker build -t ${DOCKER_IMAGE} .'
|
||||
|
||||
sh label: 'Install dgoss', script: '''
|
||||
curl -s -L https://github.com/aelsabbahy/goss/releases/latest/download/goss-linux-amd64 -o goss
|
||||
@ -44,22 +46,15 @@ pipeline {
|
||||
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'
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
script {
|
||||
sh '''
|
||||
az login --identity
|
||||
az acr login --name ${ACR_NAME}
|
||||
docker push ${DOCKER_IMAGE}
|
||||
'''
|
||||
junit testResults: '**/*pytest_junit.xml'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user