Jenkins 2.103下如何获取上游项目的成功构建编号?
Hey there, let's work through this Jenkins problem you're facing. I know it's frustrating when a plugin doesn't show up and forum fixes don't pan out—let's break this down into actionable steps, including a plugin-free solution that might work better for your Pipeline setup.
Option 1: Grab the Build Number Directly with Jenkins Pipeline Script (No Plugin Needed)
Since you're using Pipeline projects, you don't actually need the Parameterized Build Plugin to fetch A's last successful build number. Just add this code to your Pipeline B's Jenkinsfile:
// Fetch the parent job object by its full name def parentJob = Jenkins.instance.getItemByFullName('A') // Get the last successful build number (the ? prevents errors if there's no successful build yet) def lastSuccessBuildNum = parentJob.getLastSuccessfulBuild()?.number if (lastSuccessBuildNum) { echo "Parent Pipeline A's last successful build number is: ${lastSuccessBuildNum}" // Use this number directly in your subsequent Pipeline steps } else { echo "Warning: Parent Pipeline A hasn't had a successful build yet." }
Heads up: The first time you run this script, Jenkins will block it for security reasons. Just head to
Manage Jenkins→In-process Script Approvaland approve the required method calls (likegetItemByFullNameandgetLastSuccessfulBuild) to let it run.
Option 2: Fix the Missing Parameterized Build Plugin
If you still want to use the plugin, the "not showing up" issue is almost certainly a version compatibility problem with your older Jenkins 2.103 instance:
- Go to
Manage Jenkins→Manage Plugins→Availabletab, search forParameterized Build Plugin. - Check the plugin's compatibility notes—skip the latest version, and pick an older release that explicitly supports Jenkins 2.103 (look for versions tagged with compatibility for 2.x Jenkins instances).
- Install the compatible version, restart Jenkins, and check your project configuration page again—the parameterized build options should appear.
Quick Recommendation
For Pipeline projects, Option 1 is usually the better route. It avoids plugin dependency headaches, is more flexible, and fits natively with Jenkins Pipeline's scripting capabilities. You can use the fetched build number directly in your Pipeline steps without having to set up parameterized builds.
内容的提问来源于stack exchange,提问作者Slok

