See https://github.com/jenkinsci/workflow-cps-global-lib-plugin
Hope that helps! On Thu, May 26, 2016 at 12:37 AM Sverre Moe <sverre....@gmail.com> wrote: > Yes, I came across it, but there is so little information about how to use > this and how it works. > The only thing I could find was this example here > https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples/global-function > which I did not understand much of. > > // The call(body) method in any file in workflowLibs.git/vars is exposed > as a method with the same name as the file. > In any file in "workflowLibs.git/vars": Where is this location? > > Jenkinsfile > standardBuild { > environment = 'golang:1.5.0' > mainScript = ''' > go version > go build -v hello-world.go > ''' > postScript = ''' > ls -l > ./hello-world > ''' > } > > standardBuild.groovy > def call(body) { > def config = [:] > body.resolveStrategy = Closure.DELEGATE_FIRST > body.delegate = config > body() > stage 'checkout' > node { > checkout scm > stage 'main' > docker.image(config.environment).inside { > sh config.mainScript > } > stage 'post' > sh config.postScript > } > } > > What is body? > What does this do? > body.resolveStrategy = Closure.DELEGATE_FIRST > > From what I could understand it would seem standardBuild in Jenkinsfile > runs the code within call(body) and variables defined in this function in > the Jenkinsfile is accessible through body.delegate = config somewhat, but > why that way around and not config = body.delegate > > Why is there no def in front of variables in standardBuild? > def mainScript > > Where do I place the file standardBuild.groovy? > > > onsdag 25. mai 2016 22.54.29 UTC+2 skrev Baptiste Mathus følgende: > >> Did you possibly have a look at: >> https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin >> or >> https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin >> ? >> > 2016-05-24 16:00 GMT+02:00 Sverre Moe <sverr...@gmail.com>: >> > What is the best design approach to keeping the Jenkinsfile small (little >>> build logic as possible)? >>> >>> Having close to a hundred projects and several branches on each, then >>> duplicating the pipeline logic within each Jenkinsfile would be a >>> maintenance nightmare. >>> >>> 1) >>> I could put the Pipeline script within Jenkins Scriptler >>> def packageInformation = load >>> '../../../scriptler/scripts/package-information.groovy' >>> packageInformation.init() >>> However I'm only able to access this on the master node >>> >>> 2) >>> I could have all the pipeline scripts within a jenkins-ci-scripts >>> project in Git. >>> stage 'Init' >>> git url: 'ssh://g...@git.company.com/tools/jenkins-ci-scripts.git' >>> stash includes: '**/*.groovy', name: 'scripts' >>> >>> stage 'Checkout' >>> checkout scm >>> unstash scripts >>> def packageInformation = load >>> 'src/main/groovy/com/company/pipeline/package-information.groovy' >>> packageInformation.init() >>> I could then load the pipeline scripts from this stash. However I do not >>> like having to duplicate even this much in all my different Jenkinsfile. >>> >>> 3) >>> We have a inhouse build tool installed on all build machines. This >>> contains various build scripts, shell, python, ruby. >>> >>> >>> Example Jenkinsfile with little logic as possible >>> def branch = env.BUILD_BRANCH >>> def pipeline = load '/path/to/our/installed/build-pipeline.groovy' >>> parallel pipeline.nodes(branch) >>> >>> >>> My current Jenkins instance I comprised of Multi-configuration >>> jobs/projects (a jenkins job/project for each release branch). Having aprox >>> 8 release branches for each of the 60 projects. I am moving over to >>> Pipeline because of a complex workflow and because Multi-configuration does >>> not support a Prebuild-step that I need. >>> >> -- >>> You received this message because you are subscribed to the Google >>> Groups "Jenkins Users" group. >>> >> To unsubscribe from this group and stop receiving emails from it, send an >>> email to jenkinsci-use...@googlegroups.com. >> >> >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com >>> <https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > You received this message because you are subscribed to the Google Groups > "Jenkins Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to jenkinsci-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAN4CQ4ypqPgRiU8g2hDhj4oHKGy_HJuR%3DsC_O9JTBO74ni5Dcw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.