Pipeline Model Definition from within a global shared library?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pipeline Model Definition from within a global shared library?

Tim Downey
Hi,

Is it possible to run a pipeline model definition job from within a shared global library?  I'm trying to take the whole pipeline model and extract it into a simple shared lib.  I'm trying to take something like this:

https://github.com/jenkins-infra/pipeline-library/blob/master/vars/buildPlugin.groovy

But use the actual pipeline model definition inside.  The linked example above is using base pipeline behavior, not the more idiomatic pipeline model version.  I'm trying to do this to produce a common, simple Jenkinsfile across many components that all have the exact same build.  I'm trying to abstract it into a buildComponent.groovy so that my Jenkinsfile for an individual build just has:


buildComponent
()

To demonstrate, I've simplified buildComponent.groovy down to barebones.

#!/usr/bin/env groovy


def call(Map params = [:]) {

    def task = {
        pipeline {
            stages {
                stage('do-something') {
                    steps {
                        echo "do something"
                    }
                }
            }
        }
    }

    task()
}

When I try and build a Jenkinsfile using buildComponent(), I get this for an error:

[Pipeline] End of Pipeline
[Bitbucket] Notifying pull request build result
[Bitbucket] Build result notified
java.lang.NullPointerException: Cannot get property 'stages' on null object
	at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172)
	at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils.attachDeclarativeActions(Utils.groovy:198)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils$attachDeclarativeActions$7.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:65)
	at buildAngularComponent.call(/var/jenkins_home/jobs/angularui/jobs/van-angularui-affix/branches/PR-7/builds/13/libs/vantage-global-pipeline-libs/vars/buildAngularComponent.groovy:7)
	at buildAngularComponent.call(/var/jenkins_home/jobs/angularui/jobs/van-angularui-affix/branches/PR-7/builds/13/libs/vantage-global-pipeline-libs/vars/buildAngularComponent.groovy:18)
	at WorkflowScript.run(WorkflowScript:2)

Am I trying to do something that is not currently possible?  I admit that I'm confused by the levels of indirection going on.

Thanks,
Tim

--
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/18c8171b-6c13-4fe8-9a5e-2ac330054ac0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pipeline Model Definition from within a global shared library?

Tim Downey
Closing the loop on this in case it helps out someone else.  This is not currently possible.  See JENKINS-42224 for more info.

Thanks Andrew Bayer for letting me know.

On Wednesday, March 8, 2017 at 3:11:31 PM UTC-5, Tim Downey wrote:
Hi,

Is it possible to run a pipeline model definition job from within a shared global library?  I'm trying to take the whole pipeline model and extract it into a simple shared lib.  I'm trying to take something like this:

<a href="https://github.com/jenkins-infra/pipeline-library/blob/master/vars/buildPlugin.groovy" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkins-infra%2Fpipeline-library%2Fblob%2Fmaster%2Fvars%2FbuildPlugin.groovy\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGcYy-DnTAiL_f5cNc6wuuy_qNtTw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fjenkins-infra%2Fpipeline-library%2Fblob%2Fmaster%2Fvars%2FbuildPlugin.groovy\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGcYy-DnTAiL_f5cNc6wuuy_qNtTw&#39;;return true;">https://github.com/jenkins-infra/pipeline-library/blob/master/vars/buildPlugin.groovy

But use the actual pipeline model definition inside.  The linked example above is using base pipeline behavior, not the more idiomatic pipeline model version.  I'm trying to do this to produce a common, simple Jenkinsfile across many components that all have the exact same build.  I'm trying to abstract it into a buildComponent.groovy so that my Jenkinsfile for an individual build just has:


buildComponent
()

To demonstrate, I've simplified buildComponent.groovy down to barebones.

#!/usr/bin/env groovy


def call(Map params = [:]) {

    def task = {
        pipeline {
            stages {
                stage('do-something') {
                    steps {
                        echo "do something"
                    }
                }
            }
        }
    }

    task()
}

When I try and build a Jenkinsfile using buildComponent(), I get this for an error:

[Pipeline] End of Pipeline
[Bitbucket] Notifying pull request build result
[Bitbucket] Build result notified
java.lang.NullPointerException: Cannot get property 'stages' on null object
	at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60)
	at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:172)
	at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils.attachDeclarativeActions(Utils.groovy:198)
	at org.jenkinsci.plugins.pipeline.modeldefinition.Utils$attachDeclarativeActions$7.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
	at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
	at org.jenkinsci.plugins.pipeline.modeldefinition.ModelInterpreter.call(jar:file:/var/jenkins_home/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy:65)
	at buildAngularComponent.call(/var/jenkins_home/jobs/angularui/jobs/van-angularui-affix/branches/PR-7/builds/13/libs/vantage-global-pipeline-libs/vars/buildAngularComponent.groovy:7)
	at buildAngularComponent.call(/var/jenkins_home/jobs/angularui/jobs/van-angularui-affix/branches/PR-7/builds/13/libs/vantage-global-pipeline-libs/vars/buildAngularComponent.groovy:18)
	at WorkflowScript.run(WorkflowScript:2)

Am I trying to do something that is not currently possible?  I admit that I'm confused by the levels of indirection going on.

Thanks,
Tim

--
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/832af430-3471-403a-8b4b-d1246b9cc8e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.