Coding a new type of agent

45 views
Skip to first unread message

Ivan Pavlović

unread,
May 16, 2024, 1:44:00 PMMay 16
to jenkin...@googlegroups.com, Carlos Sanchez
Hi all,

I have been looking into the kubernetes plugin for jenkins as an inspiration for my own plugin i would like to write. This plugin should provide a new type of agent that can be used in the declarative pipeline. Also, it would need to provide users an option to create a new type of cloud. 

So far, i have been able to implement all that is needed for a new type of cloud, but i can't seem to figure out what would be extension points to provide a new type of agent.

If you wonder why i am using kubernetes plugin for Jenkins as an inspiration, it's because this new agent will communicate with an open source batch job scheduler called Armada. Armada operates on top of k8s clusters, and it receives a yaml manifest that it interprets and knows how to communicate with k8s API to deploy pods and schedule jobs. So i don't need to integrate with k8s API directly. 

Example like this, taken from the homepage of kubernetes plugin:
```
pipeline {
  agent {
    kubernetes {
      yaml '''
        apiVersion: v1
        kind: Pod
        metadata:
          labels:
            some-label: some-label-value
        spec:
          containers:
          - name: maven
            image: maven:alpine
            command:
            - cat
            tty: true
          - name: busybox
            image: busybox
            command:
            - cat
            tty: true
        '''
      retries 2
    }
  }
  stages {
    stage('Run maven') {
      steps {
        container('maven') {
          sh 'mvn -version'
        }
        container('busybox') {
          sh '/bin/busybox'
        }
      }
    }
  }
}
```

should now be:
```
pipeline {
  agent {
    armada {
      yaml '''
        ...
        '''
      retries 2
    }
  }
  stages {
    ....
  }
}
```

Can you help me out in implementing something like this?

Thanks!

Best regards,
Ivan

Carlos Sanchez

unread,
May 16, 2024, 2:26:06 PMMay 16
to Ivan Pavlović, jenkin...@googlegroups.com
It's been a while but I believe that for the declarative agent
definition you need something like KubernetesDeclarativeAgent [1] In
that dir you can find the other declarative pipeline code

I would not bring all the options from the k8s plugin as it has a lot
of accumulated cruft. You can do with just the declarative pipeline
options and yaml definitions without needing UI setup as it the k8s
plugin was initially implemented

If you want to look at the very basics of the plugin implementation
with declarative pipeline support you can back in history to [2]

[1] https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesDeclarativeAgent.java
[2] https://github.com/jenkinsci/kubernetes-plugin/tree/c12cb70b3118079b1054b4579eedc326c0e09ac7/src/main/java/org/csanchez/jenkins/plugins/kubernetes

Ivan Pavlović

unread,
May 17, 2024, 9:10:24 AMMay 17
to Carlos Sanchez, jenkin...@googlegroups.com
Thank you Carlos, i'll take a look at those two links, and come back to you.

Best regards,
Ivan

Jesse Glick

unread,
May 17, 2024, 12:30:50 PMMay 17
to jenkin...@googlegroups.com
On Thu, May 16, 2024 at 2:26 PM Carlos Sanchez <car...@apache.org> wrote:
It's been a while but I believe that for the declarative agent
definition you need something like KubernetesDeclarativeAgent

Yes, but better to start by getting everything to work in Scripted syntax by having a `Cloud` able to provision agents matching some label, and some block-scoped `Step` able to temporarily define such a label based on a YAML spec. The Declarative agent type is a pretty small bit of syntactic sugar on top of that.

Ivan Pavlović

unread,
May 17, 2024, 3:24:39 PMMay 17
to jenkin...@googlegroups.com
Hi Jesse,

Can you please share more details about your suggestion? Code examples?

Best regards,
Ivan

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1RCHfeYtFpHthONQ0fXHW9K2awgNRGXLH18PDsFMQ03w%40mail.gmail.com.

Jesse Glick

unread,
May 17, 2024, 4:31:18 PMMay 17
to jenkin...@googlegroups.com
On Fri, May 17, 2024 at 3:24 PM Ivan Pavlović <iv...@gr-oss.io> wrote:
Can you please share more details about your suggestion? Code examples?

 Best to study the `kubernetes` plugin.
Reply all
Reply to author
Forward
0 new messages