remote-file-plugin
remote-file-plugin copied to clipboard
How to load .groovy file relative to remote jenkinsfile?
The standard way to load a .groovy file next to the Jenkinsfile is like this:
node('node') {
stage('load') {
code = load 'common.groovy'
}
}
This tries to load a .groovy file relative to the project source code which is different when using the remote-file-plugin. One way would be to find the path where the remote jenkinsfile repository is checked out (some ...@script) path but I can't seem to figure this out.
The RJPP_JENKINSFILE variable seems almost useful but it's a relative path.
I know that I could use a separate "jenkins library" but having shared .groovy code inside a repo with centralized Jenkinsfile seems like it should work.
Best solution I found is
void checkoutRemoteJenkinsSource(String path='remote-jenkins') {
checkout scmGit(
branches: [[name: env.RJPP_BRANCH]],
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: path,
]],
userRemoteConfigs: [[
credentialsId: 'jenkins@gitea-token',
url: env.RJPP_SCM_URL
]]
)
}
But that still requires a secondary checkout