Trying to configure pod retention value for Jenkins Kubernetes plugin using groovy script. kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.Podretention.Never()) method is failing to configure with below error :
Invalid value provided in main configuration No signature of method: static org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never() is applicable for argument types: () values: []
tried configuring by using different values for the method: kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.Never)
Error using the above value as well.
Please someone help me with this as I was struck with this from quite along.
Below is the code:
import java.util.logging.Logger
import hudson.*
import hudson.model.*
import java.io.PrintWriter
import java.io.StringWriter
import jenkins.*
import jenkins.install.InstallState
import jenkins.model.*
import jenkins.util.xml.*
import javax.xml.xpath.*
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import org.jenkinsci.plugins.plaincredentials.impl.*
import org.jenkinsci.plugins.docker.commons.credentials.*
import org.csanchez.jenkins.plugins.kubernetes.*
import org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention
KubernetesCloud kubernetes = new KubernetesCloud('test')
kubernetes.setServerUrl('http://test_url')
kubernetes.setMaxRequestsPerHostStr(20)
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
kubernetes.setWaitForPodSec(90)
// documentation reference
https://javadoc.jenkins.io/plugin/kubernetes/
// Method used setPodRetention(PodRetention podRetention) Set the global pod retention policy for the plugin.
Can some let me know how to set the pod retention value with values never , always etc.
You are missing new keyword that is required to create an object. The line
kubernetes.setPodRetention(org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
Should be
kubernetes.setPodRetention(new org.csanchez.jenkins.plugins.kubernetes.pod.retention.PodRetention.Never())
To configure global pod retention policy go to https://jenkins_url/configure (or https://jenkins_url/configureClouds in latest lts version of jenkins) and update "Pod Retention" configuration grouped under Kubernetes Cloud