# Jenkins for Kubernetes how to retry agent initialization

**URL:** <https://community.jenkins.io/t/jenkins-for-kubernetes-how-to-retry-agent-initialization/9011>\
**Category:** Ask a question\
**Created:** [August 12, 2023, 8:38am UTC](https://community.jenkins.io/t/jenkins-for-kubernetes-how-to-retry-agent-initialization/9011 "2023-08-12T08:38:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![makeevolution](https://avatars.discourse-cdn.com/v4/letter/m/6a8cbe/32.png) [@makeevolution](https://community.jenkins.io/u/makeevolution)\
**Post date:** [August 12, 2023, 8:38am UTC](https://community.jenkins.io/t/jenkins-for-kubernetes-how-to-retry-agent-initialization/9011/1 "2023-08-12T08:38:25Z")

</div>

Hi, I am using the Jenkins for Kubernetes plugin, and in the documentation I saw the following to implement retries:

```auto
pipeline {
  agent {
    kubernetes {
      yaml '''
        apiVersion: v1
        kind: Pod
        metadata:
          labels:
            some-label: some-label-value
        spec:
          containers:
          - name: maven
            image: maven:alpine
            imagePullPolicy: always
            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'
        }
      }
    }
  }
}

```

However, it also does a retry if the stage has an issue (not a exit 1 from the sh) e.g. pod loss during the shell execution. I would like to only do the retry if there is an issue with the pod initialization e.g. if the image pull for the maven image fails. Is there a way to achieve this i.e. retry only the agent initialization and not the stages themselves?

---

<div class="post-metadata">

**Author:** ![melvilgit](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/melvilgit/32/13124_2.png) [@melvilgit](https://community.jenkins.io/u/melvilgit)\
**Post date:** [February 12, 2025, 10:21pm UTC](https://community.jenkins.io/t/jenkins-for-kubernetes-how-to-retry-agent-initialization/9011/2 "2025-02-12T22:21:00Z")

</div>

Did you figure out the solution for this ?
