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

Bitbucket Pipelines上传至Artifactory时构建名称异常求助

Fixing Artifactory Build Name Mismatch in Bitbucket Pipelines

Let's tackle that build name issue you're facing—since everything else is working, it's likely a small configuration tweak or environment mismatch causing the problem. Here's how to debug and fix it:

1. First, Fix That Command Line Syntax

Looking at your Pipelines command, there's a critical typo: you have a space between - and Partifactory_user (should be -Partifactory_user without the space). Gradle won't recognize the parameter with that space, so it's probably falling back to default values for your build name. Correct the command to:

bash ./gradlew build artifactoryPublish -Partifactory_user=$ARTIFACTORY_USER -Partifactory_password=$ARTIFACTORY_PASSWORD

2. Explicitly Set Build Name in Your Gradle Config

The most common reason for unexpected build names is not explicitly defining buildName in the Artifactory plugin configuration. Add this to your Gradle file's artifactory block to lock in the name you want:

artifactory {
    contextUrl = "https://your-artifactory-instance-url" // Update to your actual Artifactory URL
    publish {
        repository {
            repoKey = "your-target-repo" // e.g., 'libs-release-local' or your custom repo key
            username = project.getProperty('artifactory_user')
            password = project.getProperty('artifactory_password')
        }
        defaults {
            publications('mavenJava') // Match your configured publication name
            // Set build name to your project name, or use a Bitbucket env var for repo-specific names
            buildName = project.name 
            // Use Bitbucket's built-in build number for consistency in Pipelines
            buildNumber = System.getenv('BITBUCKET_BUILD_NUMBER') ?: 'local-dev-build'
        }
    }
}

If you want the build name to tie directly to your Bitbucket repo, swap project.name with System.getenv('BITBUCKET_REPO_SLUG')—this will use your repo's slug as the build name in Pipelines, while falling back to the local project name when you run builds on your machine.

3. Verify Environment Variable Access in Pipelines

Sometimes Pipelines doesn't pass environment variables as expected. Add a debug step to your bitbucket-pipelines.yml to check if the variables (and any others you're using for build name) are available:

steps:
  - step:
      name: Debug Environment & Gradle Properties
      script:
        - echo "BITBUCKET_REPO_SLUG: $BITBUCKET_REPO_SLUG"
        - echo "BITBUCKET_BUILD_NUMBER: $BITBUCKET_BUILD_NUMBER"
        - ./gradlew properties | grep -E "(buildName|buildNumber)"

Compare this output to what you see locally when running ./gradlew properties—this will tell you if the build name is being overridden or not set correctly in the Pipelines environment.

4. Update Your Artifactory Plugin Version

Older versions of the Gradle Artifactory plugin have bugs around build name propagation. Make sure you're using a recent version in your build.gradle:

plugins {
    id "com.jfrog.artifactory" version "4.32.0" // Check for the latest stable version
    id "maven-publish"
}

Once you make these changes, re-run your Pipeline—your build name should now match what you expect. If it's still off, share the output of the debug step and your full Gradle config, and we can dig deeper.

内容的提问来源于stack exchange,提问作者isaac weathers

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:48:03