Read a file in my JenkinsFile located on the master e.g. readTrusted('pod.yaml')?

Right now I read an external podTemplate from a file in my Jenkinsfile with:

podTemplate(label: podLabel, yaml: readTrusted('pod.yaml')) {
  timestamps {
    node(podLabel) {

      stage('Checkout') {
        checkout scm
      }

      stage('Info') {
        sh 'whoami'  
        container('gradle') {
          sh 'whoami'
        }
      }
    }
  }
}

where pod.yaml is located in the same repo that is being checked out on the agent.

But is it possible to specify I want to read that file from the master/controller instead so I don’t have to store it in each repo?

I know I can create podTemplates on the master using e.g. JCASC but until then I would like I simple getting started approach where I just read a file from the master - if possible?

It seems weird to me to purposely try to do a hacky work around for a problem where you know the proper solution.

would reading it from a shared library work? The bonus would be that the shared library would be version controlled. You could make a function that returned yaml read via libraryResource

1 Like