68 lines
2.4 KiB
Plaintext
68 lines
2.4 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
ASP_ENVIRONMENT = 'Production'
|
|
}
|
|
|
|
stages {
|
|
stage ('Unit Tests') {
|
|
steps {
|
|
script {
|
|
withCredentials([string(credentialsId: 'unit-test-path', variable: 'UNIT_TEST_PATH')]){
|
|
sh "dotnet test ${UNIT_TEST_PATH}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Checkout') {
|
|
steps {
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
|
|
stage ('Push to Docker Registry') {
|
|
steps {
|
|
script {
|
|
def version = "0.0.${env.BUILD_NUMBER}"
|
|
def imageName = "clean-architecture-backend:${version}"
|
|
|
|
// Usando withCredentials para manejar el REGISTRY_URL
|
|
withCredentials([string(credentialsId: 'docker-registry-url', variable: 'REGISTRY_URL')]) {
|
|
// Aquí usamos env.REGISTRY_URL para asegurarnos de que estamos usando la variable de entorno correcta
|
|
def fullImageName = "https://dockerregistry.alexdev.es/${imageName}"
|
|
|
|
// Construir la imagen
|
|
sh "docker build --build-arg ENVIRONMENT=${env.ASP_ENVIRONMENT} -t ${imageName} ./CleanArchitecture/"
|
|
|
|
// Iniciar sesión y subir la imagen
|
|
docker.withRegistry('https://dockerregistry.alexdev.es', 'dockerregistryalexdev') {
|
|
echo "Vamos a ejecutar el docker tag"
|
|
sh "docker tag clean-architecture-backend:${version} dockerregistry.alexdev.es/clean-architecture-backend:${version}"
|
|
echo "Vamos a ejecutar el docker push"
|
|
sh "docker push dockerregistry.alexdev.es/clean-architecture-backend:${version}"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
stage ('Clean Local Docker Image') {
|
|
steps {
|
|
script {
|
|
def version = "0.0.${env.BUILD_NUMBER}"
|
|
// Eliminar la imagen del agente de Jenkins
|
|
sh "docker rmi clean-architecture-backend:${version}"
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} //stages
|
|
}
|