Skip to main content
Assuming you have already configured a global (trusted) shared library in Jenkins, this guide shows how to import and call that library from a Jenkins pipeline (Jenkinsfile). The steps below explain how to verify the library resolution, update your Jenkinsfile to use shared steps, and confirm the library was loaded at runtime. On the Jenkins settings page where you configured the global trusted pipeline library, after clicking Save and refreshing the page Jenkins will display the branch it resolved and the commit ID. This confirms Jenkins can connect to and read the shared library repository.
A screenshot of the Jenkins "Global Trusted Pipeline Libraries" settings page showing a configured library named "dasher-trusted-shared-library" with the default version set to "main." The form shows several options (checkboxes), retrieval method "Modern SCM," and "Save" / "Apply" buttons.
Tip: use the commit ID shown in Jenkins to verify the exact revision being used. How to import the shared library in your Jenkinsfile
  • Remove any duplicated local Groovy function (for example, a locally-defined Slack notification function) you previously used.
  • Add the @Library annotation with the same library name you configured in Jenkins, followed by a single underscore on its own line. The underscore completes the library import syntax used by declarative pipelines.
Example Jenkinsfile header (imports the library and shows the surrounding pipeline structure):
The underscore (_) after @Library('...') is required syntax to complete the import statement in a pipeline script. It does not modify runtime behavior beyond loading the shared library.
Shared library implementation (callable step) In the shared library repository, reusable pipeline steps are defined as Groovy files under the appropriate directory (for example, vars/ in a typical shared library). When a file defines def call(...), it becomes available in the pipeline as a step named after the file (e.g., slackNotification if the file is slackNotification.groovy). Example slackNotification.groovy implementation:
Modify your Jenkinsfile to call the shared library step Replace the removed local function call with a direct call to the shared library step. When referencing the build outcome, prefer currentBuild.currentResult because it is initialized early and avoids null/"null" ambiguity. Example post block:
Use currentBuild.currentResult instead of currentBuild.result when reporting the final build status. currentBuild.result may be null until explicitly set, while currentBuild.currentResult reflects the current outcome (defaults to "SUCCESS" early in the run).
Commit and push your Jenkinsfile changes to the branch your organization job monitors. Jenkins will detect the push and schedule a new run for that branch. Pipeline activity and verification After pushing the change, the organization pipeline will schedule a new run for your branch. You can inspect the run from the organization or repository pipeline activity page.
A screenshot of the Jenkins web interface showing the "Gitea-Organization / solar-system" pipeline activity. It lists recent builds for the feature/advanced-demo branch with run numbers, commit IDs, messages, durations and status icons (success, failure, running).
When the run completes you should receive the Slack notification sent by the shared library step. To confirm the library was loaded, open the classic console output for the run and filter for the term “library”. The log shows the library resolution, cloning, and which revision was used. Example filtered console output (trimmed for clarity):
Later in the log you should also see the Slack send step showing the values provided by the shared library:
Quick reference table Summary
  • Import the shared library into your Jenkinsfile using @Library('your-library-name') _.
  • Implement reusable steps in the shared library by creating files that define def call(...).
  • Invoke those steps directly from your pipeline (for example: slackNotification("${currentBuild.currentResult}")).
  • Use currentBuild.currentResult to report the build result reliably.
  • Manage library versions by referencing branches/tags configured in Jenkins.
Links and references

Watch Video