Bitbucket Pipelines上传至Artifactory时构建名称异常求助
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

