0

I have a Jenkins pipeline which runs an application in cloud using Kubernetes plugin.

So far, I have a simple yaml file which configures a pod. The Jenkins pipeline creates a pod and it does some operations (It's parsing some data).

I've created a service (with 1 replica) which I deployed and I want to use that in Jenkins instead of creating the same pod everytime I run.

Can someone please advise how to do that? Currently this is how I am running the pipeline:

stage('Parse logs') {
    agent {
        kubernetes {
            cloud 'sandbox'
            label 'log-parser'
            yamlFile 'jenkins/logparser.yaml'
        }
    }
    when {
        beforeAgent true
        expression { params.parse_logs }
    }
    steps {
        container('log-parser'') {
            sh '/usr/local/openjdk-11/bin/java -jar /opt/log-parser/log-parser.jar --year=$year --month=$month --day=$day --hour=$hour
        }
    }
} 

Can you please advise how to use the created service 'log-parser' instead of creating a pod everytime I run the pipeline?

Dragos Roban
  • 479
  • 2
  • 11
  • 20
  • Which version of Kubernetes did you use and how did you set up the cluster? Did you use bare metal installation or some cloud providor? Which exactly plugin did you use? – Mikołaj Głodziak Oct 07 '21 at 10:38
  • It's actually not quite possible as far as I tested. What I got to do, I created an independent service and I linked the pods created by the Jenkins plugin to that service using labels and selectors. This can be found on the official documentation. – Dragos Roban Oct 20 '21 at 07:36

0 Answers0