• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • kubernetes-plugin
    • Jenkins 2.150.1
      Kubernetes::Pipeline::DevOps Steps 1.5
      Kubernetes::Pipeline::Kubernetes Steps 1.5
      Kubernetes::Plugin 1.14.0

      I'd like to move pod definition from pipeline to a file resource in a shared library.
       
      My pipeline is like:

      pipeline {
          agent none
          stages {     
              stage('step-in-kubernetes') {
                  agent {
                      kubernetes {
                          label 'kube'
                          yamlFile libraryResource('myPod.yaml')
                      }
                  }       
                  stages {
                      stage('Checkout') {
                          steps {
                              checkout([$class: 'MercurialSCM', clean: true,
                                  source: 'https://acme.com/hg/myproject'])
                          }
                      }
      
                  } 
              }
          }
      }
      

       
      I put 'myPod.yaml' in resources folder of my library.
      I get an error saying that HG is not installed.

      But:

      • it's work if I used yaml property instead of yamlFile
      • libraryResource fails when using wrong filename
         

          [JENKINS-55299] Read pod template yaml from library resource

          Issue $JENKINS-52259 adds yamlFile attribute to kubernetes agent

          Arnaud Bourree added a comment - Issue $ JENKINS-52259 adds yamlFile attribute to kubernetes agent

          "libraryResource" returns a string, not file, you can load pod templates from resource files this like so:

          pipeline {
            agent {
              kubernetes {
                label "Jenkins-${env.JOB_NAME}"
                yaml libraryResource('pod_templates/kube_agent.yaml')
              }
            }
          }
          

           

          Alex Zeleznikov added a comment - "libraryResource" returns a string, not file, you can load pod templates from resource files this like so: pipeline { agent { kubernetes { label "Jenkins-${env.JOB_NAME}" yaml libraryResource( 'pod_templates/kube_agent.yaml' ) } } }  

          Your right, I should used yaml and not yamlFile because that is libraryResource which reads from file, not kubernetes plugin.

          I'll close the issue

           

          Arnaud Bourree added a comment - Your right, I should used yaml and not yamlFile because that is libraryResource which reads from file, not kubernetes plugin. I'll close the issue  

          libraryResource read from file, we should use yaml and not yamlFile

          Arnaud Bourree added a comment - libraryResource read from file, we should use yaml and not yamlFile

          i tried to use this way. 

          Now i can see the pod created , but it will be terminated after 12 seconds.

          And console output shows: 

           hudson.remoting.ProxyException: java.lang.Throwable: waiting here
          		at io.fabric8.kubernetes.client.utils.Utils.waitUntilReady
          ....
          hudson.remoting.ProxyException: io.fabric8.kubernetes.client.KubernetesClientException: container build is not valid for pod
          at io.fabric8.kubernetes.client.dsl.internal.ExecWebSocketListener.onFailure(
          	at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:571)
          ... 

           

          Abdennour Toumi added a comment - i tried to use this way.  Now i can see the pod created , but it will be terminated after 12 seconds. And console output shows:  hudson.remoting.ProxyException: java.lang.Throwable: waiting here at io.fabric8.kubernetes.client.utils.Utils.waitUntilReady .... hudson.remoting.ProxyException: io.fabric8.kubernetes.client.KubernetesClientException: container build is not valid for pod at io.fabric8.kubernetes.client.dsl.internal.ExecWebSocketListener.onFailure( at okhttp3.internal.ws.RealWebSocket.failWebSocket(RealWebSocket.java:571) ...  

            csanchez Carlos Sanchez
            arnaud Arnaud Bourree
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: