Pipeline Model Definition from within a global shared library?

176 views
Skip to first unread message

Tim Downey

unread,
Mar 8, 2017, 3:11:31 PM3/8/17
to Jenkins Users
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:


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

Tim Downey

unread,
Mar 9, 2017, 2:07:07 PM3/9/17
to Jenkins Users
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.
Reply all
Reply to author
Forward
0 new messages