Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-56546

Pod Yaml in Jenkinsfile not being honored

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Not A Defect
    • Component/s: kubernetes-plugin, pipeline
    • Labels:
      None
    • Environment:
    • Similar Issues:

      Description

      We are running Jenkins in kubernetes and using the Kubernetes plugin(https://github.com/jenkinsci/kubernetes-plugin) to start agents for each build.

      It seems like there is some kind of reuse of the pod yaml that is declared in the Jenkinsfile.

      This can be reproduced with these steps and this example Jenkinsfile:

      def getYaml() {
        return """
      apiVersion: v1
      kind: Pod
      metadata:
        annotations:
          iam.amazonaws.com/role: redacted
        labels:
          branch: ${env.BRANCH_NAME.take(63)}
          build-number: ${env.BUILD_NUMBER}
      spec:
        tolerations:
        - key: "builder"
          operator: "Equal"
          value: "nvme"
          effect: "NoSchedule"
        nodeSelector:
          kops.k8s.io/instancegroup: redacted
        containers:
        - name: jnlp
          image: 'redacted:3.4.0'
          args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
          workingDir: /workdir
          volumeMounts:
          - mountPath: /home/jenkins/ephemeral
            name: ephemeral
          - mountPath: /home/jenkins/shared-cache
            name: shared-cache
          - mountPath: /workdir
            name: workspace-volume
          resources:
            requests:
              memory: "8192Mi"
              cpu: "4000m"
            limits:
              memory: "16384Mi"
              cpu: "8000m"
        volumes:
        - name: ephemeral
          hostPath:
            path: /media/ephemeral
            type: Directory
        - name: shared-cache
          nfs:
            server: redacted
            path: /
      """
      }pipeline {
          agent {
              kubernetes {
                label 'jnlp'
                defaultContainer 'jnlp'
                yaml getYaml()
              }
          }
          options { 
            timestamps () 
            timeout(time: 1, unit: 'HOURS')
            disableConcurrentBuilds()
          }
          triggers {
              pollSCM('') // Enabling being build on Push
          }
          environment {
          }    stages {
              stage('Shipit') {
                  steps {
                      withCredentials([
                        string(credentialsId: 'NPM_TOKEN', variable: 'NPM_TOKEN'),
                      ]) {
                          ansiColor('xterm') {
                              script {
                                  sh 'echo stuff'
                              }
                          }
                      }
                  }
              }
          }
      }

       

      1. Have a multibranch pipeline setup with a Jenkinsfile in the repository

      2. Create a branch called branch-a in your git repository

      3. Create a branch called branch-b in your git repository

      4. Edit the pod yaml in branch-a an commit to branch-a

      5. Push branch-a upstream, this will trigger a build

      6. Wait for the agent to start for the build

      7. Push branch-b upstream, this will trigger a build. Now the branch-a and branch-b builds are running in parallel

      8. Notice that the pod yaml in the second build is identical to the pod yaml in the first build even though you made no changes to branch-b

       

        Attachments

          Activity

          Hide
          csanchez Carlos Sanchez added a comment -

          jenkins is reusing your agent because they both are using the same label jnlp

          Show
          csanchez Carlos Sanchez added a comment - jenkins is reusing your agent because they both are using the same label jnlp

            People

            • Assignee:
              csanchez Carlos Sanchez
              Reporter:
              purkhusid Daníel P
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: