From 5be60e3ff9b2a6c7136f4c87c1b6bcc2eeb37ba1 Mon Sep 17 00:00:00 2001 From: mateuszwojcik Date: Tue, 3 Jun 2025 22:01:21 +0000 Subject: [PATCH] Add Jenkinsfile --- Jenkinsfile | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..04daed2 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,83 @@ +pipeline { + agent { + label "docker-agent-dsrv02" + } + + environment { + DOCKER_REGISTRY = 'gitea.postio.pl' + IMAGE_NAME = 'oxdr-swagger-ui' + } + + parameters { + string(name: 'BUILD_ID', defaultValue: 'latest', description: 'Image tag / build identifier') + } + + stages { + stage('Checkout') { + steps { + git branch: 'main', credentialsId: 'postio-bot-gitea', url: 'https://gitea.postio.pl/postio/microservice-repository.git' + } + } + + stage('Generate Swagger Docs') { + agent { + docker { + image 'bufbuild/buf:latest' + args '--entrypoint=' + reuseNode true + } + } + environment { + BUF_CACHE_DIR="${env.WORKSPACE}/.cache" + } + steps { + dir("${env.WORKSPACE}") { + echo "Generating Swagger documentation..." + sh "buf generate" + } + } + } + stage('Convert OpenAPI to v3') { + agent { + docker { + image 'python:3-bookworm' + reuseNode true + } + } + steps { + dir("${env.WORKSPACE}") { + echo "Converting OpenAPI V2 to V3..." + sh "python3 scripts/process_openapiv2.py" + } + } + } + + stage('Build Docker Image') { + steps { + echo "Building Docker image..." + sh "docker build -t ${DOCKER_REGISTRY}/${IMAGE_NAME}:${BUILD_ID} -f deployments/docker/Dockerfile deployments/docker/" + } + } + + stage('Push Docker Image') { + steps { + withCredentials([usernamePassword( + credentialsId: 'docker-registry-creds', // <-- Update to your Jenkins credentials ID + usernameVariable: 'DOCKER_USER', + passwordVariable: 'DOCKER_PASS' + )]) { + echo "Logging into Docker registry..." + sh "echo $DOCKER_PASS | docker login ${DOCKER_REGISTRY} -u $DOCKER_USER --password-stdin" + echo "Pushing Docker image..." + sh "docker push ${DOCKER_REGISTRY}/${IMAGE_NAME}:${BUILD_ID}" + } + } + } + } + + post { + failure { + echo "Build failed. Check the console output for details." + } + } +}