Reputation: 5099
I have the following structure:
/Jenkinsfile/script2.groovy
/Jenkinsfile/pipeline2.yaml
script1.groovy
pipeline1.yaml
There's a reference in script1 to the pipeline using:
yamlFile "pipeline1.yml"
or
yamlFile "./Jenkinsfiles/pipeline2.yaml"
And works fine. I'm trying to use the same pipeline file on script2 but can't make it work.
Here's the relevant part of the script:
pipeline {
agent {
kubernetes {
cloud "xxxx"
yamlFile "pipeline.yml"
}
}
Any idea?
Note: pipeline1 and pieline2 are the same files just showing different locations.
Upvotes: 0
Views: 1192
Reputation: 11
Given the directory structure you mentioned:
.
├── Jenkinsfile
│ ├── pipeline2.yaml
│ └── script2.groovy
├── pipeline1.yaml
└── script1.groovy
The following files can be read from within their parent directory as follows:
For script1 ran from ./
groovy ./script1.groovy
is able to read both ./pipeline1.yaml
and ./Jenkinsfile/pipeline2.yaml
For Script2 ran from ./
groovy ./Jenkinsfile/script2.groovy
is able to read ./pipeline1.yaml
, since its in the same directory the file ./Jenkinsfile/script2.groovy
is being run from i.e. ./
groovy ./Jenkinsfile/script2.groovy
is able to read ./Jenkinfile/pipeline2.yaml
also because the path is relative.
I think you could possibly simplify this by just having the files reside in one directory. And also using the syntax readYaml(file: './nameOfFile.yaml')
readyaml section.
.
├── pipeline1.yaml
├── script1.groovy
├── pipeline2.yaml
└── script2.groovy
Upvotes: 1