Read a file from on the Controller workspace at pipeline start

We run our Jenkins instances 100% under Kubernetes through the Kubernetes plugin. One benefit is that we can then have better control of the container images that will run the business workload of each pipelines.

In order to simplify our jenkinsfile we use a Jenkins Library that generates the YAML we pass to kubernetes agent definition:

            agent {
                kubernetes {
                    yamlMergeStrategy merge()
                    yaml getK8sPod(env.STAGE_NAME, mem: '500Mi')
                }
            }

The container tage to us is stored in the repository as a yaml file. We want to read the yaml file from the controller so we can get the data without having to rely on a running agent.

We already have the logic working if we run from an agent pod inside a pipeline step, but if we try to do that from outside a step we get:

Perhaps you forgot to surround the fileExists step with a step that provides this, such as: node

This is the jenkins lib code that works from a node, but fails when run from outside a node:

        String pipeline_conf_file = 'pipeline_conf.yaml'
        if (fileExists(pipeline_conf_file)) {
            global_cache._conf = readYaml(file: pipeline_conf_file)
        }

I suspect we will have to call plain groovy code to read the files directly, but also figure out the workspace folder path on the controller.

Furthermore we will want to make an authenticated http call to fetch the yaml from a remote server if it is not present in the current repository.

Any pointer on how to get this will be appreciated.