jenkinsci / ghprb-plugin

github pull requests builder plugin for Jenkins
https://plugins.jenkins.io/ghprb/
MIT License
498 stars 606 forks source link

${ghprbActualCommit} does not pick up current commit from hook if an additional branch is specified. #833

Open NathanZookCH opened 2 years ago

NathanZookCH commented 2 years ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.332.2 OS: Linux - 5.11.0-1022-aws --- ace-editor:1.1 antisamy-markup-formatter:2.7 apache-httpcomponents-client-4-api:4.5.13-1.0 bootstrap4-api:4.6.0-3 bootstrap5-api:5.1.3-6 bouncycastle-api:2.25 branch-api:2.1044.v2c007e51b_87f caffeine-api:2.9.2-29.v717aac953ff3 checks-api:1.7.2 cloudbees-folder:6.714.v79e858ef76a_2 command-launcher:1.6 credentials:1087.1089.v2f1b_9a_b_040e4 credentials-binding:1.27.1 display-url-api:2.3.6 durable-task:495.v29cd95ec10f2 echarts-api:5.3.0-2 email-ext:2.87 external-monitor-job:191.v363d0d1efdf8 font-awesome-api:6.0.0-1 ghprb:1.42.2 git:4.11.0 git-client:3.11.0 git-server:1.10 github:1.34.3 github-api:1.301-378.v9807bd746da5 handlebars:3.0.8 jackson2-api:2.13.2-260.v43d711474c77 javax-activation-api:1.2.0-2 javax-mail-api:1.6.2-5 jaxb:2.3.0.1 jdk-tool:1.5 jnr-posix-api:3.1.7-3 jquery-detached:1.2.1 jquery3-api:3.6.0-2 jsch:0.1.55.2 junit:1.58 ldap:2.8 mailer:408.vd726a_1130320 matrix-auth:3.1 matrix-project:758.v7a_ea_491852f3 momentjs:1.1.1 okhttp-api:4.9.3-105.vb96869f8ac3a pam-auth:1.7 pipeline-graph-analysis:188.v3a01e7973f2c pipeline-input-step:447.v95e5a_6e3502a_ pipeline-stage-step:291.vf0a8a7aeeb50 plain-credentials:1.8 plugin-util-api:2.16.0 popper-api:1.16.1-2 popper2-api:2.11.5-1 rake:1.8.0 resource-disposer:0.18 scm-api:595.vd5a_df5eb_0e39 script-security:1145.vb_cf6cf6ed960 snakeyaml-api:1.29.1 ssh-agent:1.24.1 ssh-credentials:1.19 ssh-slaves:1.806.v2253cedd3295 sshd:3.228.v4c9f9e652c86 structs:308.v852b473a2b8c timestamper:1.17 token-macro:285.vff7645a_56ff0 trilead-api:1.57.v6e90e07157e1 windows-slaves:1.8 workflow-api:1143.v2d42f1e9dea_5 workflow-cps:2686.v7c37e0578401 workflow-durable-task-step:1128.v8c259d125340 workflow-job:1174.vdcb_d054cf74a_ workflow-scm-step:2.13 workflow-step-api:622.vb_8e7c15b_c95a_ workflow-support:817.v58126df57338 ws-cleanup:0.41 ```

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

Ubuntu 20.04 on AWS

Java 11 on controller and worker nodes.

Reproduction steps

  1. Set up job with two branches specified, one using ${ghprbActualCommit}, the other specifying refs/heads/master.
  2. Create pull request.
  3. Observe that the code actually checked out & used for the test is not from the pull request.

Expected Results

The code checked out & used for the test should be from the pull request.

Actual Results

The code checked out & used for the test is from a different commit (presumably master).

Anything else?

No response

Sti2nd commented 2 years ago

I think I am also experiencing this. Although I have only one "Branch specifier" in Jenkins I have refspec of origin and PRs. Using ${ghprbActualCommit} does not work, Jenkins check out an old commit. Using {sha1} works, but then we are building the merge commit.

Something interesting: After one have built with {sha1} and then try to change back to ${ghprbActualCommit} the old commit it chooses are the commit that were used for the merge in {sha1}.

I think it is related or the same bug as this https://github.com/jenkinsci/ghprb-plugin/issues/683

Sti2nd commented 2 years ago

Update: I began using the Pipeline: Multibranch plugin instead