From 28c67973b31f700baa9d02eebbcb574b3e265cff Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 7 Jan 2026 15:19:48 -0500 Subject: [PATCH 1/5] Use `CredentialsProvider.findCredentialByIdInItem` --- pom.xml | 9 +++++++- .../filesystem/BitbucketSCMFileSystem.java | 11 +++------- .../util/BitbucketCredentialsUtils.java | 21 ++++++++----------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 359860ac6..7911df747 100644 --- a/pom.xml +++ b/pom.xml @@ -69,10 +69,17 @@ io.jenkins.tools.bom bom-${jenkins.baseline}.x - 5543.vfd758c7c868d + 5804.v80587a_38d937 import pom + + + org.jenkins-ci.plugins + credentials + + 1469.vb_13b_4cfb_391d + diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java index d1baa55e1..9a71e76a7 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java @@ -33,7 +33,6 @@ import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit; import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils; import com.cloudbees.jenkins.plugins.bitbucket.impl.util.DateUtils; -import com.cloudbees.plugins.credentials.CredentialsMatchers; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.common.StandardCredentials; import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder; @@ -234,20 +233,16 @@ private static StandardCredentials lookupScanCredentials(@CheckForNull Item cont if (scanCredentialsId == null) { return null; } else { - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + var c = CredentialsProvider.findCredentialByIdInItem( + scanCredentialsId, StandardCredentials.class, context, context instanceof Queue.Task task ? task.getDefaultAuthentication2() : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverURL).build() - ), - CredentialsMatchers.allOf( - CredentialsMatchers.withId(scanCredentialsId), - AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)) - ) ); + return AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; } } diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java index a19fea1b0..36d6c77a5 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java @@ -141,14 +141,13 @@ public static T lookupCredentials(@CheckForNull : ACL.SYSTEM2; List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + return CredentialsProvider.findCredentialByIdInItem( + credentialsId, type, item, authentication, domainRequirements - ), - CredentialsMatchers.withId(credentialsId)); + ); } return null; } @@ -161,13 +160,12 @@ public static T lookupCredentials(@CheckForNull if (StringUtils.isNotBlank(credentialsId)) { List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItemGroup( + return CredentialsProvider.findCredentialByIdInItemGroup( + credentialsId, type, itemGroup, null, - domainRequirements), - CredentialsMatchers.withId(credentialsId)); + domainRequirements); } return null; } @@ -188,13 +186,12 @@ public static FormValidation checkCredentialsId(@CheckForNull SCMSourceOwner con : ACL.SYSTEM2; List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - StandardCertificateCredentials certificateCredentials = CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + StandardCertificateCredentials certificateCredentials = CredentialsProvider.findCredentialByIdInItem( + credentialsId, StandardCertificateCredentials.class, context, authentication, - domainRequirements), - CredentialsMatchers.withId(credentialsId)); + domainRequirements); if (certificateCredentials != null) { return FormValidation.warning("A certificate was selected. You will likely need to configure Checkout over SSH."); } From 9fdb9db37054d6a712a513dbe2f85a9609ceb860 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 7 Jan 2026 15:26:28 -0500 Subject: [PATCH 2/5] Forgot null check --- .../plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java index 9a71e76a7..e156f607f 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java @@ -242,7 +242,7 @@ private static StandardCredentials lookupScanCredentials(@CheckForNull Item cont : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverURL).build() ); - return AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; + return c != null && AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; } } From fd3302d6e19ddd3dd32a8ba0883e5378ddffb892 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 7 Jan 2026 15:19:48 -0500 Subject: [PATCH 3/5] Use `CredentialsProvider.findCredentialByIdInItem` --- pom.xml | 9 +++++++- .../filesystem/BitbucketSCMFileSystem.java | 11 +++------- .../util/BitbucketCredentialsUtils.java | 21 ++++++++----------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 359860ac6..7911df747 100644 --- a/pom.xml +++ b/pom.xml @@ -69,10 +69,17 @@ io.jenkins.tools.bom bom-${jenkins.baseline}.x - 5543.vfd758c7c868d + 5804.v80587a_38d937 import pom + + + org.jenkins-ci.plugins + credentials + + 1469.vb_13b_4cfb_391d + diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java index d1baa55e1..9a71e76a7 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java @@ -33,7 +33,6 @@ import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit; import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils; import com.cloudbees.jenkins.plugins.bitbucket.impl.util.DateUtils; -import com.cloudbees.plugins.credentials.CredentialsMatchers; import com.cloudbees.plugins.credentials.CredentialsProvider; import com.cloudbees.plugins.credentials.common.StandardCredentials; import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder; @@ -234,20 +233,16 @@ private static StandardCredentials lookupScanCredentials(@CheckForNull Item cont if (scanCredentialsId == null) { return null; } else { - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + var c = CredentialsProvider.findCredentialByIdInItem( + scanCredentialsId, StandardCredentials.class, context, context instanceof Queue.Task task ? task.getDefaultAuthentication2() : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverURL).build() - ), - CredentialsMatchers.allOf( - CredentialsMatchers.withId(scanCredentialsId), - AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)) - ) ); + return AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; } } diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java index a19fea1b0..36d6c77a5 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/util/BitbucketCredentialsUtils.java @@ -141,14 +141,13 @@ public static T lookupCredentials(@CheckForNull : ACL.SYSTEM2; List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + return CredentialsProvider.findCredentialByIdInItem( + credentialsId, type, item, authentication, domainRequirements - ), - CredentialsMatchers.withId(credentialsId)); + ); } return null; } @@ -161,13 +160,12 @@ public static T lookupCredentials(@CheckForNull if (StringUtils.isNotBlank(credentialsId)) { List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - return CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItemGroup( + return CredentialsProvider.findCredentialByIdInItemGroup( + credentialsId, type, itemGroup, null, - domainRequirements), - CredentialsMatchers.withId(credentialsId)); + domainRequirements); } return null; } @@ -188,13 +186,12 @@ public static FormValidation checkCredentialsId(@CheckForNull SCMSourceOwner con : ACL.SYSTEM2; List domainRequirements = URIRequirementBuilder.fromUri(serverURL).build(); - StandardCertificateCredentials certificateCredentials = CredentialsMatchers.firstOrNull( - CredentialsProvider.lookupCredentialsInItem( + StandardCertificateCredentials certificateCredentials = CredentialsProvider.findCredentialByIdInItem( + credentialsId, StandardCertificateCredentials.class, context, authentication, - domainRequirements), - CredentialsMatchers.withId(credentialsId)); + domainRequirements); if (certificateCredentials != null) { return FormValidation.warning("A certificate was selected. You will likely need to configure Checkout over SSH."); } From d147562f4fe42f12186ff788a271c250f5e65a7b Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Wed, 7 Jan 2026 15:26:28 -0500 Subject: [PATCH 4/5] Forgot null check --- .../plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java index 9a71e76a7..e156f607f 100644 --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/filesystem/BitbucketSCMFileSystem.java @@ -242,7 +242,7 @@ private static StandardCredentials lookupScanCredentials(@CheckForNull Item cont : ACL.SYSTEM2, URIRequirementBuilder.fromUri(serverURL).build() ); - return AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; + return c != null && AuthenticationTokens.matcher(BitbucketAuthenticator.authenticationContext(serverURL)).matches(c) ? c : null; } } From 94a659c3259d60b4fb6b409e85b8281d833efba5 Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Mon, 12 Jan 2026 12:52:52 -0500 Subject: [PATCH 5/5] Dep released --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7911df747..e988d0e49 100644 --- a/pom.xml +++ b/pom.xml @@ -77,8 +77,7 @@ org.jenkins-ci.plugins credentials - - 1469.vb_13b_4cfb_391d + 1480.v2246fd131e83