如何在Jenkins流水线任务中为制品添加指纹?
Hey there! Let's walk through how to get fingerprints set up for your Maven artifacts in Jenkins Pipeline, building on the configuration you already have.
First, let's confirm your current setup is on the right track: you're using the withMaven block with both artifactsPublisher(disabled: false) and dependenciesFingerprintPublisher(disabled: false)—that's exactly the foundation you need. Here's how to ensure fingerprints are properly applied to your artifacts:
1. Verify Automatic Fingerprinting is Enabled
The artifactsPublisher option already tells Jenkins to upload your built Maven artifacts (like JARs/WARs from the target directory) and automatically generate fingerprints for them when enabled. Similarly, dependenciesFingerprintPublisher handles fingerprinting for your project's dependencies.
Just make sure your pom.xml is configured to produce artifacts correctly (using plugins like maven-install-plugin or maven-deploy-plugin so artifacts end up in the target folder)—this lets the Pipeline Maven plugin detect and process them.
2. Manual Fingerprinting (For Edge Cases)
If automatic fingerprinting doesn't pick up your artifacts (e.g., custom output directories, non-standard artifact names), you can explicitly tell Jenkins which files to fingerprint using the fingerprint step inside your pipeline:
pipeline { agent any stages { stage('Build & Fingerprint') { steps { withMaven(options: [ artifactsPublisher(disabled: false), dependenciesFingerprintPublisher(disabled: false) ]) { sh 'mvn clean package' // Explicitly fingerprint all JAR/WAR files in target fingerprint 'target/*.jar', 'target/*.war' } } } } }
This ensures Jenkins creates fingerprints for the specified files, even if the automatic publisher misses them.
3. Validate Fingerprints Were Generated
After running a build, you can confirm fingerprints are working by:
- Checking the Fingerprints tab on your Jenkins job page—this lists all fingerprinted artifacts and dependencies.
- Looking for logs like
Recording fingerprintsin your build output—this indicates Jenkins successfully processed the files. - Viewing the artifact details in Jenkins; fingerprinted files will show a small fingerprint icon next to them.
That should cover it! Between the withMaven options and explicit fingerprint steps, your artifacts should have proper fingerprints tracked in Jenkins.
内容的提问来源于stack exchange,提问作者IsaacE

