You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins 2.103下如何获取上游项目的成功构建编号?

Fixing the Issue: Get Parent Pipeline A's Last Successful Build Number in Pipeline B

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 Approval and approve the required method calls (like getItemByFullName and getLastSuccessfulBuild) 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 → Available tab, search for Parameterized 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 04:06:30