// Jenkins Shared Library · Apache 2.0
jenkins-beansh-step
Native BeanShell scripting support for Jenkins Pipelines as a first-class step, complementing Groovy without replacing it. Write portable scripts that run the same on Windows, Linux and macOS.
BeanShell 2.1.1
Jenkins 2.x+
Cross-platform
POSIX-like commands
// Requirements
What you need
// jenkins
Jenkins 2.x or higher
// plugin
Git plugin for Jenkins
// Installation
Setting up Jenkins
01
Go to Global Trusted Pipeline Libraries
Navigate to Manage Jenkins > System > Global Trusted Pipeline Libraries and click Add.
02
Fill in the library fields
| Field | Value |
|---|---|
| Name | beansh |
| Default version | main |
| Load implicitly | ✅ |
| Retrieval method | Modern SCM |
| Source Code Management | Git |
| Project Repository | https://codeberg.org/rrangelo/jenkins-beansh-step.git |
03
Save
Click Save. Press Approve script if prompted.
// Usage
Running BeanShell scripts
// Note: BeanShell requires semicolons (;) at the end of each statement.
Inline · Single line
pipeline {
agent any
stages {
stage('Example') {
steps {
beansh 'print("Hello!");'
}
}
}
}
Inline · Multiline
pipeline {
agent any
stages {
stage('Example') {
steps {
beansh '''
print("Line 1");
print("Line 2");
print("Line 3");
'''
}
}
}
}
pipeline {
agent any
stages {
stage('Example') {
steps {
beansh 'source(".jenkins/scripts/report.bsh");' }
}
}
}
// Variables
Variables from the Pipeline
// Variables defined before a source() call are automatically inherited by the sourced script.
pipeline {
agent any
stages {
stage('Example') {
steps {
beansh """
buildNumber = "${BUILD_NUMBER}";
print("Build number: " + buildNumber);
"""
}
}
}
}
// POSIX-like commands
Built-in commands
pwd()Print current working directory
cd(path)Change directory
cat(file)Print file contents
cp(from, to)Copy file
dir()List directory contents
exec(command)Execute a system command
run(file)Run a .bsh script in an isolated context