This commit is contained in:
Ramón Vásquez 2025-10-29 15:59:47 -03:00
parent 5a4a07f18b
commit aafb9b5b0c

47
Jenkinsfile vendored
View file

@ -2,11 +2,52 @@ pipeline {
agent any agent any
stages { stages {
stage('Build') { stage('Checkout') {
steps { steps {
echo 'Building...' checkout scm
sh 'docker build -t my-python-app .'
} }
} }
stage('Build Image') {
steps {
echo 'Building image...'
// --pull ensures base layer is fresh; tag includes BUILD_NUMBER to avoid cache clashes
sh 'docker build --pull -t my-python-app:${BUILD_NUMBER} .'
}
}
stage('Run Container') {
steps {
echo 'Running container...'
// --rm cleans up; this will print "Hello, World!" to the console
sh 'docker run --rm --name my-python-app-${BUILD_NUMBER} my-python-app:${BUILD_NUMBER}'
}
}
stage('(Optional) Verify Output') {
steps {
script {
// Re-run capturing output to assert expected behavior (example)
def out = sh(
script: 'docker run --rm my-python-app:${BUILD_NUMBER}',
returnStdout: true
).trim()
if (out != 'Hello, World!') {
error "Unexpected output: '${out}'"
}
}
}
}
}
post {
always {
// Best-effort cleanup of any leftover container/image for this build tag
sh '''
docker rm -f my-python-app-${BUILD_NUMBER} 2>/dev/null || true
docker image rm my-python-app:${BUILD_NUMBER} 2>/dev/null || true
'''
}
} }
} }
``