dotnet.worker/Jenkinsfile

88 lines
3 KiB
Text
Raw Normal View History

2026-01-06 13:59:38 -03:00
pipeline {
agent any
options { skipDefaultCheckout(true) }
environment {
IMAGE_NAME = 'rd.jenkins'
2026-01-06 15:41:33 -03:00
AWS_URL = credentials('aws-ecr-url')
AWS_USER = credentials('aws-ecr-username')
AWS_REGION = credentials('aws-ecr-region')
2026-01-06 13:59:38 -03:00
AWS_CREDS_ID = 'aws-jenkins'
}
stages {
stage('Checkout') {
steps {
cleanWs()
script {
checkout scm
sh 'git submodule update --init --recursive'
2026-01-06 16:13:25 -03:00
def branch = sh(
2026-01-06 16:14:26 -03:00
script: "git branch --show-current",
2026-01-06 16:13:25 -03:00
returnStdout: true
).trim()
if(branch != 'main') {
echo "[!] Not on 'main' branch. Current branch: ${branch}"
2026-01-06 16:09:22 -03:00
currentBuild.result = 'SUCCESS'
error("Stopping pipeline: not on main branch.")
2026-01-06 16:13:25 -03:00
}
2026-01-06 16:09:22 -03:00
2026-01-06 13:59:38 -03:00
def tagName = sh(
script: "git describe --tags --exact-match 2>/dev/null || echo 'no-tag'",
returnStdout: true
).trim()
echo "Detected tag: ${tagName}"
2026-01-06 14:05:19 -03:00
if (!(tagName ==~ /^v[0-9]+(\.[0-9]+){0,2}$/)) {
echo "[!] Invalid tag format. Expected format: vX.Y.Z"
2026-01-06 13:59:38 -03:00
currentBuild.result = 'SUCCESS'
error("Stopping pipeline: invalid tag format.")
}
env.IMAGE_TAG = tagName
2026-01-06 14:09:39 -03:00
env.AWS_IMAGE = "${AWS_URL}/${AWS_USER}/${IMAGE_NAME}:${IMAGE_TAG}"
2026-01-06 13:59:38 -03:00
}
}
}
2026-01-06 15:41:33 -03:00
// stage('Build Image') {
2026-01-06 13:59:38 -03:00
// steps {
2026-01-06 15:41:33 -03:00
// sh "echo ${AWS_IMAGE}"
// script {
// docker.build("${AWS_IMAGE}", '-f src/worker/Dockerfile ./src/worker/ --no-cache')
// // docker.build("${AWS_IMAGE}", '--no-cache --pull -f src/Service/Infrastructure/App/Dockerfile .')
2026-01-06 13:59:38 -03:00
// }
// }
// }
2026-01-06 15:41:33 -03:00
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}"
"""
}
}
}
}
2026-01-06 13:59:38 -03:00
// stage('Push Image') {
// steps {
// sh "docker push ${AWS_IMAGE}"
// }
// }
}
}