jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
216 stars 353 forks source link

Jenkins Custom checkout fails for PR jobs #819

Open dsakilesh opened 7 months ago

dsakilesh commented 7 months ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.440.1 OS: Linux - 5.15.0-1053-aws Java: 17.0.10 - Eclipse Adoptium (OpenJDK 64-Bit Server VM) --- Office-365-Connector:4.21.0 Parameterized-Remote-Trigger:3.2.0 ace-editor:1.1 amazon-ecr:1.114.vfd22430621f5 amazon-ecs:1.49 analysis-model-api:12.1.0 ansicolor:1.0.4 ant:497.v94e7d9fffa_b_9 antisamy-markup-formatter:162.v0e6ec0fcfcf6 apache-httpcomponents-client-4-api:4.5.14-208.v438351942757 artifactory:4.0.5 audit-trail:361.v82cde86c784e authentication-tokens:1.53.v1c90fd9191a_b_ authorize-project:1.7.1 aws-credentials:218.v1b_e9466ec5da_ aws-java-sdk:1.12.633-430.vf9a_e567a_244f aws-java-sdk-cloudformation:1.12.633-430.vf9a_e567a_244f aws-java-sdk-codebuild:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ec2:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ecr:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ecs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-efs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-elasticbeanstalk:1.12.633-430.vf9a_e567a_244f aws-java-sdk-iam:1.12.633-430.vf9a_e567a_244f aws-java-sdk-kinesis:1.12.633-430.vf9a_e567a_244f aws-java-sdk-logs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-minimal:1.12.633-430.vf9a_e567a_244f aws-java-sdk-secretsmanager:1.12.633-430.vf9a_e567a_244f aws-java-sdk-sns:1.12.633-430.vf9a_e567a_244f aws-java-sdk-sqs:1.12.633-430.vf9a_e567a_244f aws-java-sdk-ssm:1.12.633-430.vf9a_e567a_244f azure-ad:457.vf85d61f83b_26 azure-sdk:157.v855da_0b_eb_dc2 badge:1.9.1 basic-branch-build-strategies:81.v05e333931c7d bitbucket:241.v6d24a_57f9359 blueocean:1.27.11 blueocean-bitbucket-pipeline:1.27.11 blueocean-commons:1.27.11 blueocean-config:1.27.11 blueocean-core-js:1.27.11 blueocean-dashboard:1.27.11 blueocean-display-url:2.4.2 blueocean-events:1.27.11 blueocean-git-pipeline:1.27.11 blueocean-github-pipeline:1.27.11 blueocean-i18n:1.27.11 blueocean-jwt:1.27.11 blueocean-personalization:1.27.11 blueocean-pipeline-api-impl:1.27.11 blueocean-pipeline-editor:1.27.11 blueocean-pipeline-scm-api:1.27.11 blueocean-rest:1.27.11 blueocean-rest-impl:1.27.11 blueocean-web:1.27.11 bootstrap5-api:5.3.2-4 bouncycastle-api:2.30.1.77-225.v26ea_c9455fd9 branch-api:2.1152.v6f101e97dd77 build-failure-analyzer:2.5.0 build-metrics:1.3 build-monitor-plugin:1.14-860.vd06ef2568b_3f build-name-setter:2.4.1 build-timeout:1.32 build-user-vars-plugin:1.9 caffeine-api:3.1.8-133.v17b_1ff2e0599 checks-api:2.0.2 cloudbees-bitbucket-branch-source:876.v857269a_5f439 cloudbees-folder:6.901.vb_4c7a_da_75da_3 cobertura:1.17 code-coverage-api:4.99.0 command-launcher:107.v773860566e2e commons-lang3-api:3.13.0-62.v7d18e55f51e2 commons-text-api:1.11.0-95.v22a_d30ee5d36 config-file-provider:968.ve1ca_eb_913f8c configuration-as-code:1775.v810dc950b_514 configuration-as-code-groovy:1.2-SNAPSHOT (private-fd4f7109-pascal-ebike) configuration-as-code-secret-ssm:1.0.1 copyartifact:722.v0662a_9b_e22a_c coverage:1.11.1 credentials:1319.v7eb_51b_3a_c97b_ credentials-binding:657.v2b_19db_7d6e6d data-tables-api:1.13.8-4 display-url-api:2.200.vb_9327d658781 docker-commons:439.va_3cb_0a_6a_fb_29 docker-workflow:572.v950f58993843 downstream-build-cache:1.7 doxygen:178.v6ea_ef5f7dfdb dtkit-api:3.0.2 durable-task:550.v0930093c4b_a_6 ec2-fleet:3.2.0 echarts-api:5.4.3-4 email-ext:2.104 embeddable-build-status:467.v4a_954796e45d extended-choice-parameter:376.v2e02857547b_a_ extended-read-permission:53.v6499940139e5 favorite:2.208.v91d65b_7792a_c font-awesome-api:6.5.1-3 forensics-api:2.4.0 generic-webhook-trigger:2.0.0 ghprb:1.42.2 git:5.2.1 git-client:4.6.0 git-forensics:2.1.0 git-parameter:0.9.19 github:1.38.0 github-api:1.318-461.v7a_c09c9fa_d63 github-branch-source:1772.va_69eda_d018d4 global-build-stats:293.vd7b_d6e361475 gradle:2.10 groovy:457.v99900cb_85593 groovy-postbuild:228.vcdb_cf7265066 gson-api:2.10.1-15.v0d99f670e0a_7 handy-uri-templates-2-api:2.1.8-30.v7e777411b_148 htmlpublisher:1.32 http-post:1.2 http_request:1.18 influxdb:3.0.3.0001 instance-identity:185.v303dc7c645f9 ionicons-api:56.v1b_1c8c49374e jackson2-api:2.16.1-373.ve709c6871598 jakarta-activation-api:2.0.1-3 jakarta-mail-api:2.0.1-3 javadoc:243.vb_b_503b_b_45537 javax-activation-api:1.2.0-6 javax-mail-api:1.6.2-9 jaxb:2.3.9-1 jdk-tool:73.vddf737284550 jenkins-design-language:1.27.11 jjwt-api:0.11.5-77.v646c772fddb_0 job-dsl:1.87 jobConfigHistory:1229.v3039470161a_d joda-time-api:2.12.7-29.v5a_b_e3a_82269a_ jquery3-api:3.7.1-2 jsch:0.2.16-86.v42e010d9484b_ json-api:20240205-27.va_007549e895c json-path-api:2.9.0-33.v2527142f2e1d junit:1259.v65ffcef24a_88 junit-realtime-test-reporter:146.v82b_01a_5d2b_3a_ lockable-resources:1243.v346d600eea_24 mailer:463.vedf8358e006b_ mask-passwords:173.v6a_077a_291eb_5 matlab:2.12.0 matrix-auth:3.2.1 matrix-project:822.824.v14451b_c0fd42 mattermost:3.1.3 maven-plugin:3.23 mercurial:1260.vdfb_723cdcc81 metrics:4.2.21-449.v6960d7c54c69 mina-sshd-api-common:2.12.0-90.v9f7fb_9fa_3d3b_ mina-sshd-api-core:2.12.0-90.v9f7fb_9fa_3d3b_ monitoring:1.98.0 multibranch-scan-webhook-trigger:1.0.11 okhttp-api:4.11.0-172.vda_da_1feeb_c6e parameter-separator:166.vd0120849b_386 parameterized-scheduler:262.v00f3d90585cc parameterized-trigger:787.v665fcf2a_830b_ pipeline-build-step:540.vb_e8849e1a_b_d8 pipeline-graph-analysis:216.vfd8b_ece330ca_ pipeline-groovy-lib:704.vc58b_8890a_384 pipeline-input-step:491.vb_07d21da_1a_fb_ pipeline-milestone-step:111.v449306f708b_7 pipeline-model-api:2.2175.v76a_fff0a_2618 pipeline-model-definition:2.2175.v76a_fff0a_2618 pipeline-model-extensions:2.2175.v76a_fff0a_2618 pipeline-rest-api:2.34 pipeline-stage-step:305.ve96d0205c1c6 pipeline-stage-tags-metadata:2.2175.v76a_fff0a_2618 pipeline-stage-view:2.34 pipeline-utility-steps:2.16.2 plain-credentials:143.v1b_df8b_d3b_e48 plot:2.1.12 plugin-util-api:4.1.0 prism-api:1.29.0-13 prometheus:2.5.1 pubsub-light:1.18 python:1.3 rebuild:330.v645b_7df10e2a_ resource-disposer:0.23 rich-text-publisher-plugin:1.5 role-strategy:689.v731678c3e0eb_ scm-api:683.vb_16722fb_b_80b_ scmskip:45.vfdec6fb_05267 script-security:1326.vdb_c154de8669 slack:684.v833089650554 snakeyaml-api:2.2-111.vc6598e30cc65 sonar:2.17.2 sse-gateway:1.26 ssh-credentials:308.ve4497b_ccd8f4 ssh-slaves:2.948.vb_8050d697fec sshd:3.312.v1c601b_c83b_0e structs:337.v1b_04ea_4df7c8 swarm:3.44 test-results-analyzer:0.4.1 testcomplete-xunit:1.1 timestamper:1.26 token-macro:400.v35420b_922dcb_ trilead-api:2.133.vfb_8a_7b_9c5dd1 uno-choice:2.8.1 variant:60.v7290fc0eb_b_cd warnings-ng:11.0.0 workflow-aggregator:596.v8c21c963d92d workflow-api:1291.v51fd2a_625da_7 workflow-basic-steps:1042.ve7b_140c4a_e0c workflow-cps:3867.v535458ce43fd workflow-durable-task-step:1331.vc8c2fed35334 workflow-job:1400.v7fd111b_ec82f workflow-multibranch:773.vc4fe1378f1d5 workflow-scm-step:415.v434365564324 workflow-step-api:657.v03b_e8115821b_ workflow-support:865.v43e78cc44e0d ws-cleanup:0.45 xunit:3.1.4 yet-another-build-visualizer:1.16 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

LINUX

Reproduction steps

            stage("Prepare") {
                steps {
                    script {
                        cleanWs()
                        scmValues = checkout scmGit(branches: [[name: env.BRANCH_NAME]], extensions: [], userRemoteConfigs: scm.userRemoteConfigs)
                        GIT_COMMIT = scmValues.GIT_COMMIT
                        echo("Using GIT commit " + scmValues.GIT_COMMIT)
                    }
                }
            } // Prepare

Expected Results

Checkout should happen for normal branches and PR branches in jenkins pipeline.

Actual Results

Jenkins job fails with below error for PR branch jobs in jenkins. However the feature branch jobs continue to work

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

Anything else?

Checkout happened without any issues for PR branch jobs until we upgraded the bitbucket branch source plugin from 866.vdea_7dcd3008e to 876.v857269a_5f439

Are you interested in contributing a fix?

No response

RichardLagerstrom commented 7 months ago

I'm experiencing the exact same issue.

PR checkout worked on version 848.v42c6a_317eda_e. After upgrading the Bitbucket Branch Source plugin to 877.vb_b_d5243f6794 it started to fail. Master builds still functioned though.

Tried to find solutions but ended up with a rollback to 848.v42c6a_317eda_e.

This issue is highly relevant and active.

jmaasing commented 7 months ago

Same here, had to revert to Bitbucket Source plugin, with version 877 I get

git fetch --tags --force --progress -- https://xxx@bitbucket.org/yyy.git +refs/heads/*:refs/remotes/origin/* # timeout=10

and then

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

schiasileon commented 7 months ago

Same on our builds after upgrading from 866 to 874. Behavior of env.BRANCH_NAME was changed I think.

petermbauer commented 6 months ago

Same here, git rev-parse origin/PR-XXX stopped working since the PR ref is not fetched anymore by the plugin. Downgrading to 866.vdea_7dcd3008e solved it.

PayBas commented 6 months ago

Indeed https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/796 appears to have broken quite a few things. I'm also still stuck on 866.vdea_7dcd3008e as the last working version before the breaking changes, despite the release of https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/815

We use quite a lot of logic relating to git-flow, so we use stuff like:

String source = sh(returnStdout: true, script: "git rev-parse origin/PR-${env.CHANGE_ID}").trim()
String target = sh(returnStdout: true, script: "git rev-parse upstream/${env.CHANGE_TARGET}").trim()

Which no longer works, since there is no upstream remote anymore, and origin/PR-### references are no longer fetched.

To be fair: the upstream remote was kinda weird anyway when the PR source and target are the exact same repository. So having 2 Git remotes in that situation was unnecessary anyway. Reserving upstream for if (!prFromTargetRepository && scmSource.isCloud()) might actually be a good change.

But these were breaking changes nonetheless.

I guess with the new plugin version, it would be something like:

String source = sh(returnStdout: true, script: "git rev-parse origin/${env.CHANGE_BRANCH}").trim()
String target = sh(returnStdout: true, script: "git rev-parse origin/${env.CHANGE_TARGET}").trim()
rbywater commented 6 months ago

Semi-related note that the lack of a upstream remote has broken the way we were using the Git setup as we looked up what the upstream remote ref as we found it the only consistent way of getting a diff between what was changed in the branch in a way which worked with PRs from same repo vs PRs from forks. Making upstream remote ref available again would be most appreciated.

schiasileon commented 5 months ago

@andrey-fomin can you take a look if your changes are the issue here please?

querplis commented 5 months ago

regular PR' building is broken for us too, that gets introduced by [871.v28d74e8b_4226], which happens to also be a security fix: https://www.jenkins.io/security/advisory/2024-03-06/#SECURITY-3300

avosluck commented 1 month ago

The problem is still relevant