Quantcast

Pipeline: Keep the main logic outside of Jenkinsfile

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Pipeline: Keep the main logic outside of Jenkinsfile

Sverre Moe-2
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://[hidden email]/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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline: Keep the main logic outside of Jenkinsfile

Baptiste MATHUS

2016-05-24 16:00 GMT+02:00 Sverre Moe <[hidden email]>:
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://git@.../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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com.
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANWgJS7UbVAcTKQ1v1PZ5aZYnLeCxTG626yX_ywGfrLH5NA_BA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline: Keep the main logic outside of Jenkinsfile

Sverre Moe-2
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: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin or <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin?

2016-05-24 16:00 GMT+02:00 Sverre Moe <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="7VpiXCEQBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sverr...@...>:
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://<a href="http://git@git.company.com/tools/jenkins-ci-scripts.git" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;">git@.../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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="7VpiXCEQBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline: Keep the main logic outside of Jenkinsfile

Kohsuke Kawaguchi
Administrator

On Thu, May 26, 2016 at 12:37 AM Sverre Moe <[hidden email]> wrote:
Yes, I came across it, but there is so little information about how to use this and how it works. 
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:
2016-05-24 16:00 GMT+02:00 Sverre Moe <[hidden email]>:
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://git@.../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 [hidden email].

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com.
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline: Keep the main logic outside of Jenkinsfile

Sverre Moe-2
Yes, that explained a lot. Thanks.

lørdag 28. mai 2016 02.11.53 UTC+2 skrev Kohsuke Kawaguchi følgende:
See <a href="https://github.com/jenkinsci/workflow-cps-global-lib-plugin" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-cps-global-lib-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEYgMtgsrdV3pqTX6diEtsTLOaW1w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-cps-global-lib-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEYgMtgsrdV3pqTX6diEtsTLOaW1w&#39;;return true;">https://github.com/jenkinsci/workflow-cps-global-lib-plugin

Hope that helps!

On Thu, May 26, 2016 at 12:37 AM Sverre Moe <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="M5BdIRC4BAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">sverr...@...> 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 <a href="https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples/global-function" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fpipeline-examples%2Ftree%2Fmaster%2Fglobal-library-examples%2Fglobal-function\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGbgWstCYSCxeRNXPn8w-cera2Aw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fpipeline-examples%2Ftree%2Fmaster%2Fglobal-library-examples%2Fglobal-function\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGbgWstCYSCxeRNXPn8w-cera2Aw&#39;;return true;">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: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin or <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin?
2016-05-24 16:00 GMT+02:00 Sverre Moe <[hidden email]>:
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://<a href="http://git@git.company.com/tools/jenkins-ci-scripts.git" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;">git@.../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 <a href="https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="M5BdIRC4BAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/092748c4-2468-4000-92d6-6f00af0becf4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Pipeline: Keep the main logic outside of Jenkinsfile

Sverre Moe-2
I followed the instructions to get the workflowLibs.git repository from Jenkins:

SInce the repository was empty I got nonexistent ref as expected and mentioned in the instructions.
sverre@mintaka:~/workspace> git clone https://build.company.com:8443/workflowLibs.git
Cloning into 'workflowLibs'...
Checking connectivity... done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

sverre@mintaka:~/workspace3> cd workflowLibs/
sverre@mintaka:~/workspace/workflowLibs> git checkout -b master
Switched to a new branch 'master'

I added one file
src/com/company/Build.groovy

When I tried to push it didn't work
sverre@mintaka:~/workspace/workflowLibs> git push --set-upstream origin master
fatal: unable to access 'https://build.company.com:8443/workflowLibs.git/': The requested URL returned error: 403



mandag 30. mai 2016 08.03.20 UTC+2 skrev Sverre Moe følgende:
Yes, that explained a lot. Thanks.

lørdag 28. mai 2016 02.11.53 UTC+2 skrev Kohsuke Kawaguchi følgende:
See <a href="https://github.com/jenkinsci/workflow-cps-global-lib-plugin" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-cps-global-lib-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEYgMtgsrdV3pqTX6diEtsTLOaW1w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fworkflow-cps-global-lib-plugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEYgMtgsrdV3pqTX6diEtsTLOaW1w&#39;;return true;">https://github.com/jenkinsci/workflow-cps-global-lib-plugin

Hope that helps!

On Thu, May 26, 2016 at 12:37 AM Sverre Moe <[hidden email]> 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 <a href="https://github.com/jenkinsci/pipeline-examples/tree/master/global-library-examples/global-function" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fpipeline-examples%2Ftree%2Fmaster%2Fglobal-library-examples%2Fglobal-function\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGbgWstCYSCxeRNXPn8w-cera2Aw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkinsci%2Fpipeline-examples%2Ftree%2Fmaster%2Fglobal-library-examples%2Fglobal-function\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGbgWstCYSCxeRNXPn8w-cera2Aw&#39;;return true;">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: <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BRemote%2BLoader%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEgRHctcL4NkoJiH0apuo67yUzHGw&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Remote+Loader+Plugin or <a href="https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwiki.jenkins-ci.org%2Fdisplay%2FJENKINS%2FPipeline%2BShared%2BGroovy%2BLibraries%2BPlugin\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFT4WpaLBpmIluVIxa0USCRKtoFpQ&#39;;return true;">https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Shared+Groovy+Libraries+Plugin?
2016-05-24 16:00 GMT+02:00 Sverre Moe <[hidden email]>:
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://<a href="http://git@git.company.com/tools/jenkins-ci-scripts.git" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fgit%40git.company.com%2Ftools%2Fjenkins-ci-scripts.git\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFYRcriSbfVlim75dRQiEKGFEmtYQ&#39;;return true;">git@.../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 <a href="https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/126d204a-f002-4838-a67e-96d02913f7df%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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-use...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/82ee1124-fd31-4107-9a33-77c9ff041271%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/d47d5ff1-f8e7-48cf-af48-98e9f913faad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...