How to include multiple pipeline scripts into jenkinsfile
10,546
You have to use shared libraries (https://jenkins.io/doc/book/pipeline/shared-libraries/). You can define multiple groovy files with classes to return a processed object or simply creating calls with method where you define a step and the execution will be sequential.
Author by
Udaykiran R
Updated on June 25, 2022Comments
-
Udaykiran R almost 2 years
I have a jenkins file as below
pipelineJob('My pipeline job'){ displayName('display name') logRotator { numToKeep(10) daysToKeep(30) artifactDaysToKeep(7) artifactNumToKeep(1) } definition{ cps { script(readFileFromWorkspace('./cicd/pipelines/clone_git_code.groovy')) script(readFileFromWorkspace('./cicd/pipelines/install_dependencies_run_quality_checks.groovy')) } } }
with above jenkinsfile the last
script
file is replacing other scripts. Basically I have split tasks into multiple groovy files so that i wont repeat the same code in all jenkinsfile and reuse the same for other jobs as well, like I can now use theclone_git_code.groovy
script in dev build as well as QA builds. -
Raúl Salinas-Monteagudo almost 5 yearsThanks for your contribution,but I have absolutely no clue about what you are doing here. Could you please explain it a bit?
-
Rusty almost 3 yearsThis looks intriguing, but this example is very incomplete. Can you provide a thorough example of what you are doing here?