Skip to content

Jenkins Shared Library Load Error Fix

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about Jenkins Shared Library Load Error Fix. We cover key concepts, practical examples, and best practices.

Your Jenkins pipeline fails with org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Expected symbol — the shared library cannot be loaded because the syntax, source, or version is wrong.

The Problem

// WRONG — incorrect shared library import
@Library('my-lib')

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                myBuild()
            }
        }
    }
}
org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
Script1: 1: unexpected token: @Library

The @Library annotation must be followed by an underscore or an import statement. A bare @Library with no import causes a parser error.

Step-by-Step Fix

1. Use the correct @Library syntax

// RIGHT — @Library with underscore for global import
@Library('my-lib') _

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                myBuild()
            }
        }
    }
}

The underscore imports all globally defined functions from the library.

2. Import specific classes

@Library('my-lib@v1.2.3') _
import com.myorg.PipelineUtils

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                PipelineUtils.checkout()
            }
        }
    }
}

3. Configure the shared library in Jenkins

Go to Manage Jenkins > Configure System > Global Pipeline Libraries. Add your library:

  • Name: my-lib (must match @Library('my-lib'))
  • Default version: main or a tag like v1.0.0
  • Source: Git, GitHub, GitLab
  • Project repository: your library repo URL

4. Use a versioned library

// Use a specific tag
@Library('my-lib@v2.0.0') _

// Use a branch
@Library('my-lib@develop') _

5. Load the library without annotation

// Alternative to @Library — use library step
library 'my-lib@main'

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                myBuild()
            }
        }
    }
}

Expected output:

[Pipeline] load
[Pipeline] // load
[Pipeline] // stage
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS

Prevention Tips

  • Always add _ after @Library('name')
  • Configure shared libraries in Jenkins UI before using them
  • Use version tags (@v1.2.3) for production pipelines
  • Test library loading with library 'my-lib' step in a scripted pipeline
  • Check the library source repository URL and credentials

Common Mistakes with shared library

  1. Mixing let bindings with <- bindings in do notation, producing type errors
  2. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  3. Non-exhaustive pattern matches that compile with warnings then crash at runtime

These mistakes appear frequently in real-world JENKINS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why does @Library fail with "No such DSL method"?

The library loads but the method you're calling doesn't exist, or the method is defined but not annotated with @NonCPS or @Field. Check the library's vars/ directory for the method definition. Global methods in shared libraries must be in vars/YourMethod.groovy.

How do I debug a shared library that won't load?

Enable stack traces in Jenkins: System.setProperty("hudson.plugins.git.GitSCM.ALLOW_NATIVE_HOOKS", "true"). Use library 'my-lib@main' inside a node { } block for better error messages. Check Manage Jenkins > System Log for library loading logs.

Can I use multiple shared libraries in one pipeline?

Yes. @Library(['lib1"@v1"', 'lib2"@v2"']) _ loads multiple libraries. If two libraries define the same method, the last one wins. Use fully qualified method names or import specific classes to avoid naming conflicts.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro