update
This commit is contained in:
parent
5a4a07f18b
commit
aafb9b5b0c
1 changed files with 49 additions and 8 deletions
57
Jenkinsfile
vendored
57
Jenkinsfile
vendored
|
|
@ -1,12 +1,53 @@
|
|||
pipeline {
|
||||
agent any
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
steps {
|
||||
echo 'Building...'
|
||||
sh 'docker build -t my-python-app .'
|
||||
}
|
||||
}
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
``
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue