load
https://www.sourcefield.nl/post/jenkins-pipeline-tutorial/
node {
// Use the shell to create the file ‘script.groovy‘
sh ‘‘‘echo ‘
def hello(name) {
echo "Hello ${name} from script"
}
return this
‘ > script.groovy‘‘‘
def script = load ‘script.groovy‘
script.hello(‘Roy‘)
}
load from git
Loading a script from another Git repository
This requires the Pipeline Remote File Loader plugin. The example assumes you have a repository somewhere that contains a Pipeline.groovy
file, which you want to download to your Jenkins workspace.
-
Go to Manage Jenkins > Manage Plugins and install
Pipeline Remote File Loader
(without restart) -
Configure a Pipeline job and set the Pipeline script to the following:
node {
stage ‘Load pipeline script‘
def pipeline = fileLoader.fromGit(
‘Pipeline.groovy‘,
‘https://bitbucket.org/your-account/your-build-scripts.git‘,
‘master‘, // use a branch or tag
‘your-account-credential-id‘, // ID from Credentials plugin
‘‘
)
checkout scm
pipeline.execute()
}