[JIRA] (JENKINS-42807) Shared-Library Import without def causes MultipleCompilationErrorsException

3 views
Skip to first unread message

dev@dominic86.de (JIRA)

unread,
Mar 15, 2017, 10:48:01 AM3/15/17
to jenkinsc...@googlegroups.com
Dominic S. created an issue
 
Jenkins / Bug JENKINS-42807
Shared-Library Import without def causes MultipleCompilationErrorsException
Issue Type: Bug Bug
Assignee: Matthew DeTullio
Attachments: JenkinsStacktrace.txt
Components: multi-branch-project-plugin, pipeline
Created: 2017/Mar/15 2:47 PM
Environment: Jenkins 2.32.3
Priority: Minor Minor
Reporter: Dominic S.

I've just spend several hours, trying to find out why my multi-branch-pipeline project was failing until I found this problem using trial and error.

I have a multi-branch-pipeline with a shared library. That shared library is already in use with other projects and works fine. After copy & pasting some code to a new Jenkinsfile I was wondering why it did not work.

Faulty Jenkinsfile:

@Library('shared-lib@master')

testing.sayHello('World')

 

This causes the build to fail with:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 3: unexpected token: testing @ line 3, column 1.
testing.sayHello('World')
^

 

When I edit my Jenkinsfile to:

@Library('shared-lib@master')

def anything = 'nothing'

testing.sayHello('World')

 

 

it executes without any error.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

dev@dominic86.de (JIRA)

unread,
Mar 15, 2017, 10:51:01 AM3/15/17
to jenkinsc...@googlegroups.com
Dominic S. commented on Bug JENKINS-42807
 
Re: Shared-Library Import without def causes MultipleCompilationErrorsException

It doesn't matter what comes after @Library() - you could also use echo 'Hello World' instead of testing.sayHello('World')

mjdetullio@gmail.com (JIRA)

unread,
Mar 21, 2017, 12:18:02 AM3/21/17
to jenkinsc...@googlegroups.com

mjdetullio@gmail.com (JIRA)

unread,
Mar 21, 2017, 12:18:02 AM3/21/17
to jenkinsc...@googlegroups.com

mjdetullio@gmail.com (JIRA)

unread,
Mar 21, 2017, 12:18:03 AM3/21/17
to jenkinsc...@googlegroups.com

andrew.bayer@gmail.com (JIRA)

unread,
Mar 28, 2017, 6:31:02 PM3/28/17
to jenkinsc...@googlegroups.com
Andrew Bayer resolved as Not A Defect
 

So you need to follow @Library('shared-lib@master') with _ - yes, an underscore. It's annoying, but the annotation needs to be on something, and a method call doesn't count. Sorry for the inconvenience!

Change By: Andrew Bayer
Status: Open Resolved
Resolution: Not A Defect

hshinde@redhat.com (JIRA)

unread,
Aug 16, 2018, 10:19:02 AM8/16/18
to jenkinsc...@googlegroups.com
Hrishikesh Shinde commented on Bug JENKINS-42807
 
Re: Shared-Library Import without def causes MultipleCompilationErrorsException

Andrew Bayer this is not clear. Could you elaborate more on this? What d do you mean by following with underscore?

This message was sent by Atlassian JIRA (v7.10.1#710002-sha1:6efc396)

alexeyjaga@gmail.com (JIRA)

unread,
Oct 28, 2019, 12:42:02 PM10/28/19
to jenkinsc...@googlegroups.com

Hrishikesh Shinde, https://jenkins.io/blog/2017/06/27/speaker-blog-SAS-jenkins-world/

After configuring Jenkins so that it can find the shared library repository, we can load the shared library into our pipeline using the @Library('<library name>') annotation. Since Annotations are designed to annotate something that follows them, we need to either include a specific import statement, or, if we want to include everything, we can use an underscore character as a placeholder. So our basic step to load the library in a pipeline would be:

@Library('Utilities2') _
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages