Jenkins自定义脚本存储位置咨询:规范与插件使用建议
Jenkins Build Script Storage: Best Practices & Recommendations
Great question—storing build scripts outside the workspace is totally the right call, since workspaces get cleaned up automatically (either by Jenkins itself or your cleanup jobs) and you don’t want to lose critical build logic. Let’s cover the best approaches:
Recommended Storage Locations
First, let’s clear up the directory options you mentioned:
- Top pick:
$JENKINS_HOME/scriptsor$JENKINS_HOME/build-scripts
The$JENKINS_HOMEdirectory is where Jenkins stores all its core configuration, plugins, and state—most teams back this up regularly. Creating a dedicated subdirectory here keeps your scripts alongside Jenkins’ critical data, ensures Jenkins has full read/write access, and avoids permission headaches. This is the most straightforward, Jenkins-native approach. - Avoid
$JENKINS_HOME/vendor
This directory is intended for third-party plugin dependencies or bundled tools, not custom build scripts. Using it will clutter your plugin management and make it harder to distinguish between Jenkins-provided files and your own. - Skip
/var/usr/jenkins-vendor(unless required by your ops team)
System-level directories like this require extra permission configuration for Jenkins to access, and they’re often excluded from standard Jenkins backups. Only use this if your organization has a strict system-wide script management policy.
Plugins to Simplify Script Management
If you want to avoid manual directory setup and get better control over your scripts, these plugins are game-changers:
- Pipeline Shared Libraries (Official)
If you’re using Jenkins Pipeline, this is the gold standard. Store your reusable build/test/deploy scripts in a separate Git repository, then configure Jenkins to pull this library. Your pipelines can reference the scripts directly, and everything stays version-controlled, isolated from workspaces, and easy to update across jobs. - Scriptler
A lightweight plugin for managing Groovy scripts (used for pipeline logic, system admin tasks, etc.). It gives you a web UI to upload, categorize, and edit scripts without touching the filesystem, plus permission controls to restrict who can modify scripts. - Configuration as Code (JCasC)
For full infrastructure-as-code control, define all your Jenkins configuration (including script paths or inline scripts) in YAML files stored in version control. JCasC automatically syncs these configurations to Jenkins, eliminating manual directory creation and ensuring consistency across environments.
Critical Best Practices
- Always version-control your scripts
No matter where you store them in Jenkins, the source of truth should be a Git/SVN repository. Jenkins’ filesystem storage is just a working copy—version control protects you from accidental deletions, lets you roll back changes, and simplifies collaboration. - Include your script directory in backups
If you use a custom directory outside$JENKINS_HOME, make sure your backup process includes it. For$JENKINS_HOMEsubdirectories, they’ll be covered by standard Jenkins backups. - Use global variables for script paths
Instead of hardcoding paths in your jobs, define a global variable (e.g.,BUILD_SCRIPTS_DIR) in Jenkins’ system configuration. This makes it easy to adjust the location later without updating every job.
内容的提问来源于stack exchange,提问作者Bruno
相关产品推荐
相关产品推荐

