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

Kubernetes plugin declarative pipeline can't use readFile to read yaml file

      Using the following settings declarative pipeline:

      pipeline {
          agent {
              kubernetes {
                  cloud 'OpenShift'
                  label 'jenkins-agent-pod'
                  yaml readFile('k8s-podspec.yaml')
              }
          }
      ...

       

      Results in the following error from Jenkins:

      Running in Durability level: MAX_SURVIVABILITY
      [Pipeline] readFile
      Required context class hudson.FilePath is missing
      Perhaps you forgot to surround the code with a step that provides this, such as: node
      [Pipeline] End of Pipeline

       

       

          [JENKINS-51255] Kubernetes plugin declarative pipeline can't use readFile to read yaml file

          Oleg Nenashev added a comment -

          Not a K8s plugin defect IMHO. In Declarative the workspace is not mapped before creating the first agent, hence readFile() cannot work in this section AFAIK

          From where do you expect to read it? From master? or from the repo?

          Oleg Nenashev added a comment - Not a K8s plugin defect IMHO. In Declarative the workspace is not mapped before creating the first agent, hence readFile() cannot work in this section AFAIK From where do you expect to read it? From master? or from the repo?

          Andrew Bayer added a comment -

          oleg_nenashev is correct - we should probably add something to the kubernetes plugin's Declarative agent setup for doing a readTrusted of a YAML file for this sort of use case.

          Andrew Bayer added a comment - oleg_nenashev is correct - we should probably add something to the kubernetes plugin's Declarative agent setup for doing a readTrusted of a YAML file for this sort of use case.

          Kevin Carrasco added a comment - - edited

          oleg_nenashev I expect to read k8s-podspec.yaml from the repository. We would like the yaml file to be part of the source code on a separate file. For now we're including the yaml contents in the Jenkinsfile.

          Kevin Carrasco added a comment - - edited oleg_nenashev I expect to read k8s-podspec.yaml from the repository. We would like the yaml file to be part of the source code on a separate file. For now we're including the yaml contents in the Jenkinsfile.

          Andrew Bayer added a comment -

          We added a new yamlFile option as of Kubernetes plugin 1.10.0 that does what you're looking for.

          Andrew Bayer added a comment - We added a new yamlFile option as of Kubernetes plugin 1.10.0 that does what you're looking for.

            abayer Andrew Bayer
            el_psycho Kevin Carrasco
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: