test
This commit is contained in:
parent
ff22523457
commit
91cd74f708
1 changed files with 72 additions and 3 deletions
75
Jenkinsfile
vendored
75
Jenkinsfile
vendored
|
|
@ -1,15 +1,84 @@
|
||||||
pipeline {
|
pipeline {
|
||||||
agent any
|
agent any
|
||||||
|
|
||||||
|
options { skipDefaultCheckout(true) }
|
||||||
|
|
||||||
|
environment {
|
||||||
|
IMAGE_NAME = 'rd.jenkins'
|
||||||
|
|
||||||
|
AWS_URL = credentials('aws-ecr-url')
|
||||||
|
AWS_USER = credentials('aws-ecr-username')
|
||||||
|
AWS_REGION = credentials('aws-ecr-region')
|
||||||
|
AWS_CREDS_ID = 'aws-jenkins'
|
||||||
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
stage('Checkout') {
|
||||||
|
steps {
|
||||||
|
cleanWs()
|
||||||
|
|
||||||
|
script {
|
||||||
|
checkout scm
|
||||||
|
|
||||||
|
sh 'git submodule update --init --recursive'
|
||||||
|
|
||||||
|
def tagName = sh(
|
||||||
|
script: "git describe --tags --exact-match 2>/dev/null || echo 'no-tag'",
|
||||||
|
returnStdout: true
|
||||||
|
).trim()
|
||||||
|
|
||||||
|
echo "Detected tag: ${tagName}"
|
||||||
|
|
||||||
|
if (tagName == 'no-tag') {
|
||||||
|
echo "Not a tag build, skipping deployment."
|
||||||
|
currentBuild.result = 'SUCCESS'
|
||||||
|
error("Stopping pipeline: not a tag push.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(tagName ==~ /^v[0-9]+\.[0-9]+(\.[0-9]+){0,2}$/)) {
|
||||||
|
echo "[!] Invalid tag format. Expected format: vX.Y.Z.K"
|
||||||
|
currentBuild.result = 'SUCCESS'
|
||||||
|
error("Stopping pipeline: invalid tag format.")
|
||||||
|
}
|
||||||
|
|
||||||
|
env.IMAGE_TAG = tagName
|
||||||
|
env.AWS_IMAGE = "${AWS_URL}/${AWS_USER}/${IMAGE_NAME}:${IMAGE_TAG}"
|
||||||
|
|
||||||
|
echo "Tag validado: ${env.IMAGE_TAG}"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stage('Build Image') {
|
stage('Build Image') {
|
||||||
steps {
|
steps {
|
||||||
sh 'echo worker:test'
|
sh "echo ${AWS_IMAGE}"
|
||||||
script {
|
script {
|
||||||
docker.build('worker:test', '-f src/worker/Dockerfile ./src/worker/ --no-cache')
|
docker.build("${AWS_IMAGE}", '--no-cache --pull -f src/Service/Infrastructure/App/Dockerfile .')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('AWS ECR Login') {
|
||||||
|
steps {
|
||||||
|
withAWS(credentials: AWS_CREDS_ID, region: AWS_REGION) {
|
||||||
|
script {
|
||||||
|
sh """
|
||||||
|
set -euo pipefail
|
||||||
|
echo "Logging in to AWS ECR: \${AWS_URL}"
|
||||||
|
aws ecr get-login-password --region "\${AWS_REGION}" \\
|
||||||
|
| docker login --username AWS --password-stdin "\${AWS_URL}"
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Push Image') {
|
||||||
|
steps {
|
||||||
|
sh "docker push ${AWS_IMAGE}"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue