Skip to content

Commit 86e5adc

Browse files
authored
Merge pull request #368 from jenkinsci/dev
Dev
2 parents 358a15a + 9fa802b commit 86e5adc

File tree

173 files changed

+2067
-1947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2067
-1947
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ jobs:
3636

3737
steps:
3838
- name: Checkout repository
39-
uses: actions/checkout@v2
40-
39+
uses: actions/checkout@v4
40+
4141
- name: Setup Java JDK
42-
uses: actions/setup-java@v2.3.1
42+
uses: actions/setup-java@v4
4343
with:
44-
java-version: 11
45-
distribution: 'adopt'
46-
44+
java-version: 17
45+
distribution: 'temurin'
46+
4747
# Initializes the CodeQL tools for scanning.
4848
- name: Initialize CodeQL
49-
uses: github/codeql-action/init@v2
49+
uses: github/codeql-action/init@v3
5050
with:
5151
languages: ${{ matrix.language }}
5252
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -57,17 +57,17 @@ jobs:
5757
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
5858
# If this step fails, then you should remove it and run the build manually (see below)
5959
# - name: Autobuild
60-
# uses: github/codeql-action/autobuild@v2
60+
# uses: github/codeql-action/autobuild@v3
6161

6262
# ℹ️ Command-line programs to run using the OS shell.
6363
# 📚 https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
6464

6565
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
6666
# and modify them (or add more) to build your code if your project
6767
# uses a compiled language
68-
68+
6969
- name: Build with Maven
7070
run: mvn -DskipTests=true -V -ntp install
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@v2
73+
uses: github/codeql-action/analyze@v3

.github/workflows/jenkins-security-scan.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ permissions:
1515

1616
jobs:
1717
security-scan:
18-
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
18+
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2.2.1
1919
with:
2020
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
21-
# java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.
21+
java-version: 17 # Specify Java 17 to match the project requirements

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,4 @@ node_modules/*
4848
/.sts4-cache/
4949
.checkstyle
5050
.aider*
51+
.claude

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Change Log
22

3+
## 3.3.0 (2025-11-24)
4+
5+
### What's Changed
6+
7+
**New Features:**
8+
* **Draft Pull Request Support** - Add ability to detect if a Pull Request is Draft (Bitbucket Cloud only) by @nazzer23 in https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin/pull/367
9+
- New environment variable: `BITBUCKET_PULL_REQUEST_IS_DRAFT`
10+
- Returns `"true"` or `"false"` (defaults to `false` if not provided by Bitbucket)
11+
- Allows filtering/skipping builds for draft PRs in pipeline scripts
12+
13+
**Internal Improvements:**
14+
* Migrate tests from JUnit4 to JUnit5 by @strangelookingnerd in https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin/pull/369
15+
* Fix build issue in pom.xml by @s78258819-svg in https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin/pull/371
16+
17+
### Compatibility
18+
* Jenkins version: >= **2.440.3** (unchanged)
19+
* Java version: **17**
20+
21+
### New Contributors
22+
* @nazzer23 made their first contribution in https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin/pull/367
23+
24+
**Full Changelog**: https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin/compare/bitbucket-push-and-pull-request-3.1.4...bitbucket-push-and-pull-request-3.3.0
25+
326
## 3.1.4 (2024-10-29)
427

528
### Closed Issues

Jenkinsfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
/*
2+
See the documentation for more options:
3+
https://github.com/jenkins-infra/pipeline-library/
4+
*/
15
buildPlugin(
6+
forkCount: '1C', // run this number of tests in parallel for faster feedback. If the number terminates with a 'C', the value will be multiplied by the number of available CPU cores
27
useContainerAgent: true, // Set to `false` if you need to use Docker for containerized tests
38
configurations: [
4-
[platform: 'linux', jdk: 17],
9+
[platform: 'linux', jdk: 21],
510
[platform: 'windows', jdk: 17],
6-
])
7-
11+
])

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ Talking generally, there are two filters used to 'control the branches':
242242
| BITBUCKET_PULL_REQUEST_COMMENT_TEXT | Comment of BB Cloud Pull Request | PR | C + S | |
243243
| BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_SOURCE_BRANCH | Latest commit hash on the source branch | PR | C + S | |
244244
| BITBUCKET_PULL_REQUEST_LATEST_COMMIT_FROM_TARGET_BRANCH | Latest commit hash on the target branch | PR | C + S | |
245+
| BITBUCKET_PULL_REQUEST_IS_DRAFT | "true" if PR is draft, "false" otherwise| PR | C | Since 3.3.0 |
245246
| BITBUCKET_REPOSITORY_UUID | Repository identifier | P | C | |
246247
| BITBUCKET_REPOSITORY_ID | Repository identifier | P | S | |
247248
| BITBUCKET_REPOSITORY_URL | Repository URL | PR | C | |
@@ -1214,6 +1215,7 @@ pipeline {
12141215
echo "BITBUCKET_TARGET_BRANCH ${env.BITBUCKET_TARGET_BRANCH}"
12151216
echo "BITBUCKET_PULL_REQUEST_LINK ${env.BITBUCKET_PULL_REQUEST_LINK}"
12161217
echo "BITBUCKET_PULL_REQUEST_ID ${env.BITBUCKET_PULL_REQUEST_ID}"
1218+
echo "BITBUCKET_PULL_REQUEST_IS_DRAFT ${env.BITBUCKET_PULL_REQUEST_IS_DRAFT}"
12171219
echo "BITBUCKET_PAYLOAD ${env.BITBUCKET_PAYLOAD}"
12181220
12191221
echo 'Env vars for cloud push...'
@@ -1235,6 +1237,76 @@ pipeline {
12351237
}
12361238
```
12371239

1240+
## Example: Skip builds for draft pull requests (Bitbucket Cloud)
1241+
1242+
Since version 3.3.0, you can detect and skip builds for draft pull requests using the `BITBUCKET_PULL_REQUEST_IS_DRAFT` environment variable:
1243+
1244+
```groovy
1245+
pipeline {
1246+
agent any
1247+
1248+
stages {
1249+
stage('Check if Draft') {
1250+
when {
1251+
environment name: 'BITBUCKET_PULL_REQUEST_IS_DRAFT', value: 'true'
1252+
}
1253+
steps {
1254+
echo 'Skipping build for draft PR'
1255+
script {
1256+
currentBuild.result = 'NOT_BUILT'
1257+
error('Draft PRs are not built')
1258+
}
1259+
}
1260+
}
1261+
1262+
stage('Build') {
1263+
when {
1264+
environment name: 'BITBUCKET_PULL_REQUEST_IS_DRAFT', value: 'false'
1265+
}
1266+
steps {
1267+
echo 'Building non-draft PR...'
1268+
// Your build steps here
1269+
}
1270+
}
1271+
1272+
stage('Test') {
1273+
when {
1274+
environment name: 'BITBUCKET_PULL_REQUEST_IS_DRAFT', value: 'false'
1275+
}
1276+
steps {
1277+
echo 'Running tests...'
1278+
// Your test steps here
1279+
}
1280+
}
1281+
}
1282+
}
1283+
```
1284+
1285+
Or simply skip the entire pipeline at the beginning:
1286+
1287+
```groovy
1288+
pipeline {
1289+
agent any
1290+
1291+
stages {
1292+
stage('Build') {
1293+
steps {
1294+
script {
1295+
if (env.BITBUCKET_PULL_REQUEST_IS_DRAFT == 'true') {
1296+
echo 'Skipping build for draft PR'
1297+
currentBuild.result = 'NOT_BUILT'
1298+
return
1299+
}
1300+
1301+
echo 'Building...'
1302+
// Your build steps here
1303+
}
1304+
}
1305+
}
1306+
}
1307+
}
1308+
```
1309+
12381310
# Thanks and Acknowledgments
12391311

12401312
This plugin is originally based on the Sazo's fork (<https://github.com/sazo/bitbucket-plugin>)

pom.xml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
1919
<jenkins.baseline>2.440</jenkins.baseline>
2020
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
21-
<powermock.version>2.0.0</powermock.version>
2221
<hpi.compatibleSinceVersion>2.9.0</hpi.compatibleSinceVersion>
2322
<jenkins.java.level>17</jenkins.java.level>
2423
</properties>
2524

2625
<name>Bitbucket Push and Pull Request Plugin</name>
27-
<description>Bitbucket plugin for Jenkins v2.138.2 or later, allowing push and pull requests</description>
26+
<description>Bitbucket plugin for Jenkins allowing push and pull requests</description>
2827

2928
<licenses>
3029
<license>
@@ -192,13 +191,6 @@
192191
<artifactId>mockito-junit-jupiter</artifactId>
193192
<scope>test</scope>
194193
</dependency>
195-
<dependency>
196-
<groupId>org.mockito</groupId>
197-
<artifactId>mockito-inline</artifactId>
198-
<version>5.2.0</version>
199-
<scope>test</scope>
200-
</dependency>
201-
202194
</dependencies>
203195

204196
<url>https://github.com/jenkinsci/bitbucket-push-and-pull-request-plugin</url>
@@ -213,13 +205,13 @@
213205
<repositories>
214206
<repository>
215207
<id>repo.jenkins-ci.org</id>
216-
<url>https://repo.jenkins.io/public/</url>
208+
<url>https://repo.jenkins-ci.org/public/</url>
217209
</repository>
218210
</repositories>
219211
<pluginRepositories>
220212
<pluginRepository>
221213
<id>repo.jenkins-ci.org</id>
222-
<url>https://repo.jenkins.io/public/</url>
214+
<url>https://repo.jenkins-ci.org/public/</url>
223215
</pluginRepository>
224216
</pluginRepositories>
225217

@@ -243,5 +235,4 @@
243235
</plugin>
244236
</plugins>
245237
</build>
246-
247238
</project>

src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/BitBucketPPRJobProbe.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import org.eclipse.jgit.transport.URIish;
5656

5757
/**
58-
*
58+
*
5959
* @author cdelmonte
6060
*
6161
*/
@@ -92,7 +92,7 @@ public void triggerMatchingJobs(BitBucketPPRHookEvent bitbucketEvent,
9292
List<URIish> remoteScmUrls = bitbucketAction.getScmUrls().stream().map(makeUrl)
9393
.filter(Objects::nonNull).collect(Collectors.toList());
9494

95-
try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
95+
try (ACLContext ctx = ACL.as2(ACL.SYSTEM2)) {
9696
if (globalConfig.isSingleJobSet()) {
9797
try {
9898
Job job = (Job) Jenkins.get().getItemByFullName(globalConfig.getSingleJob());
@@ -159,7 +159,7 @@ && mPJobShouldNotBeTriggered(job, bitbucketEvent, bitbucketAction)) {
159159
return;
160160
}
161161

162-
Predicate<URIish> checkSCM = (url) -> scm instanceof GitSCM && matchGitScm(scm, url);
162+
Predicate<URIish> checkSCM = url -> scm instanceof GitSCM && matchGitScm(scm, url);
163163

164164
if (remotes.stream().anyMatch(checkSCM) && !scmTriggered.contains(scm)) {
165165
scmTriggered.add(scm);
@@ -230,11 +230,9 @@ private boolean mPJobShouldNotBeTriggered(Job<?, ?> job, BitBucketPPRHookEvent b
230230
}
231231

232232
private Optional<BitBucketPPRTrigger> getBitBucketTrigger(Job<?, ?> job) {
233-
if (job instanceof ParameterizedJobMixIn.ParameterizedJob) {
234-
ParameterizedJobMixIn.ParameterizedJob<?, ?> pJob =
235-
(ParameterizedJobMixIn.ParameterizedJob<?, ?>) job;
233+
if (job instanceof ParameterizedJobMixIn.ParameterizedJob<?, ?> pJob) {
236234

237-
return pJob.getTriggers().values().stream().filter(BitBucketPPRTrigger.class::isInstance)
235+
return pJob.getTriggers().values().stream().filter(BitBucketPPRTrigger.class::isInstance)
238236
.findFirst().map(BitBucketPPRTrigger.class::cast);
239237
}
240238
return Optional.empty();

src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/BitBucketPPRPollResultListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/*******************************************************************************
22
* The MIT License
3-
*
3+
*
44
* Copyright (C) 2018, CloudBees, Inc.
5-
*
5+
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
77
* associated documentation files (the "Software"), to deal in the Software without restriction,
88
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
99
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
*
1212
* The above copyright notice and this permission notice shall be included in all copies or
1313
* substantial portions of the Software.
14-
*
14+
*
1515
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
1616
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1717
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
@@ -26,7 +26,7 @@
2626

2727

2828
public interface BitBucketPPRPollResultListener {
29-
public void onPollSuccess(PollingResult pollingResult);
29+
void onPollSuccess(PollingResult pollingResult);
3030

31-
public void onPollError(Throwable throwable);
31+
void onPollError(Throwable throwable);
3232
}

0 commit comments

Comments
 (0)