-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows to see jobs which execute repository / branch scanning as users of credentials, allowing to figure out which jobs actually reference these credentials more easily.
- Loading branch information
Thomas Salzinger
committed
Mar 27, 2024
1 parent
4733e8c
commit d4babb5
Showing
3 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/com/cloudbees/jenkins/plugins/bitbucket/CredentialTrackingRunListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.cloudbees.jenkins.plugins.bitbucket; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import hudson.model.listeners.RunListener; | ||
|
||
/** | ||
* Tracks the usage of credentials | ||
*/ | ||
@Extension | ||
public class CredentialTrackingRunListener extends RunListener<Run<?, ?>> { | ||
@Override | ||
public void onInitialize(Run<?, ?> run) { | ||
final BitbucketSCMSource source = BitbucketSCMSource.findForRun(run); | ||
|
||
if (source == null) { | ||
return; | ||
} | ||
|
||
final boolean usesSshCheckout = source.getTraits().stream().anyMatch(scmSourceTrait -> scmSourceTrait instanceof SSHCheckoutTrait); | ||
|
||
if (!usesSshCheckout) { | ||
CredentialsProvider.track(run, source.credentials()); | ||
} | ||
} | ||
} |