update
This commit is contained in:
parent
9dd7d2ca73
commit
f3c4a6f8e5
1 changed files with 43 additions and 24 deletions
67
Jenkinsfile
vendored
67
Jenkinsfile
vendored
|
|
@ -1,5 +1,23 @@
|
|||
pipeline {
|
||||
agent any
|
||||
options { skipDefaultCheckout(true) }
|
||||
|
||||
environment {
|
||||
IMAGE_NAME = 'testing-python-app'
|
||||
IMAGE_TAG = 'latest'
|
||||
CONTAINER_NAME = "${IMAGE_NAME}-container"
|
||||
|
||||
AWS_URL = '231670719202.dkr.ecr.sa-east-1.amazonaws.com'
|
||||
AWS_USER = 'liesa'
|
||||
AWS_REGION = 'sa-east-1'
|
||||
AWS_CREDS_ID = 'aws-jenkins'
|
||||
AWS_REGISTRY = "${AWS_URL}/${AWS_USER}/${IMAGE_NAME}"
|
||||
AWS_IMAGE = "${AWS_REGISTRY}:${IMAGE_TAG}"
|
||||
|
||||
FORGEJO_URL = 'ssh://git@forgejo.test.dev.it.liesa.com.ar/'
|
||||
FORGEJO_OWNER = 'ramon.vasquez'
|
||||
FORGEJO_REPO = 'py_test.git'
|
||||
}
|
||||
|
||||
stages {
|
||||
stage('Checkout') {
|
||||
|
|
@ -7,12 +25,32 @@ pipeline {
|
|||
checkout scm
|
||||
}
|
||||
}
|
||||
stage('AWS ECR Login') {
|
||||
steps {
|
||||
withAWS(credentials: env.AWS_CREDS_ID, region: env.AWS_REGION) {
|
||||
script {
|
||||
def accountId = sh(
|
||||
script: 'set -euo pipefail; aws sts get-caller-identity --query Account --output text',
|
||||
returnStdout: true
|
||||
).trim()
|
||||
env.ECR_REGISTRY = "${accountId}.dkr.ecr.${env.AWS_REGION}.amazonaws.com"
|
||||
}
|
||||
sh '''
|
||||
set -euo pipefail
|
||||
echo "Logging in to AWS ECR: ${ECR_REGISTRY}"
|
||||
aws ecr get-login-password --region "$AWS_REGION" \
|
||||
| docker login --username AWS --password-stdin "$ECR_REGISTRY"
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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} .'
|
||||
sh "echo ${AWS_REGISTRY}:${IMAGE_TAG}"
|
||||
script {
|
||||
docker.build("${AWS_REGISTRY}:${IMAGE_TAG}", '-f . --no-cache --pull')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -24,29 +62,10 @@ pipeline {
|
|||
}
|
||||
}
|
||||
|
||||
stage('(Optional) Verify Output') {
|
||||
stage('Push Image') {
|
||||
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}'"
|
||||
sh 'docker push "${AWS_REGISTRY}:${IMAGE_TAG}"'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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