jenkinsci / bitbucket-branch-source-plugin

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

CHANGE_AUTHOR and CHANGE_AUTHOR_EMAIL is set to PR creator instead of latest change author #492

Open Impakt opened 3 years ago

Impakt commented 3 years ago

Version report

Jenkins and plugins versions report:

Jenkins: 2.314
OS: Linux - 5.4.109+
---
ace-editor:1.1
apache-httpcomponents-client-4-api:4.5.13-1.0
atlassian-bitbucket-server-integration:3.0.0
authentication-tokens:1.4
bitbucket:1.1.29
blueocean:1.25.0
blueocean-autofavorite:1.2.4
blueocean-bitbucket-pipeline:1.25.0
blueocean-commons:1.25.0
blueocean-config:1.25.0
blueocean-core-js:1.25.0
blueocean-dashboard:1.25.0
blueocean-display-url:2.4.1
blueocean-events:1.25.0
blueocean-git-pipeline:1.25.0
blueocean-github-pipeline:1.25.0
blueocean-i18n:1.25.0
blueocean-jwt:1.25.0
blueocean-personalization:1.25.0
blueocean-pipeline-api-impl:1.25.0
blueocean-pipeline-editor:1.25.0
blueocean-pipeline-scm-api:1.25.0
blueocean-rest:1.25.0
blueocean-rest-impl:1.25.0
blueocean-web:1.25.0
bootstrap4-api:4.6.0-3
bootstrap5-api:5.1.1-1
bouncycastle-api:2.25
branch-api:2.7.0
caffeine-api:2.9.2-29.v717aac953ff3
checks-api:1.7.2
cloudbees-bitbucket-branch-source:2.9.11
cloudbees-folder:6.16
command-launcher:1.2
config-file-provider:3.8.1
configuration-as-code:1.54
credentials:2.6.1
credentials-binding:1.27
crowd2:2.0.2
display-url-api:2.3.5
docker-build-step:2.8
docker-commons:1.17
docker-java-api:3.1.5.2
docker-plugin:1.2.3
docker-workflow:1.26
durable-task:1.39
echarts-api:5.2.1-2
favorite:2.3.3
font-awesome-api:5.15.4-1
git:4.8.2
git-client:3.10.0
git-server:1.10
github:1.34.1
github-api:1.133
github-branch-source:2.11.3
global-post-script:1.1.4
google-chat-notification:1.4
google-container-registry-auth:0.3
google-kubernetes-engine:0.8.6
google-oauth-plugin:1.0.6
h2-api:1.4.199
handlebars:3.0.8
handy-uri-templates-2-api:2.1.8-1.0
htmlpublisher:1.26
jackson2-api:2.13.0-226.v0c5dd2d2fd2a
jdk-tool:1.0
jenkins-design-language:1.25.0
jira:3.6
jjwt-api:0.11.2-9.c8b45b8bb173
jquery3-api:3.6.0-2
jsch:0.1.55.2
junit:1.53
kubernetes:1.30.2
kubernetes-cli:1.10.3
kubernetes-client-api:5.4.1
kubernetes-credentials:0.9.0
lockable-resources:2.11
mailer:1.34
matrix-project:1.19
mercurial:2.15
metrics:4.0.2.8
momentjs:1.1.1
nexus-jenkins-plugin:3.11.20210920-123737.0869e33
nodejs:1.4.0
oauth-credentials:0.4
okhttp-api:3.14.9
parameterized-scheduler:1.0
pipeline-build-step:2.15
pipeline-graph-analysis:1.11
pipeline-input-step:2.12
pipeline-maven:3.10.0
pipeline-milestone-step:1.3.2
pipeline-model-api:1.9.2
pipeline-model-definition:1.9.2
pipeline-model-extensions:1.9.2
pipeline-rest-api:2.19
pipeline-stage-step:2.5
pipeline-stage-tags-metadata:1.9.2
pipeline-stage-view:2.19
plain-credentials:1.7
plugin-util-api:2.5.0
popper-api:1.16.1-2
popper2-api:2.10.2-1
postgresql-api:42.2.5
pubsub-light:1.16
scm-api:2.6.5
script-security:1.78
snakeyaml-api:1.29.1
sse-gateway:1.24
ssh-credentials:1.19
ssh-slaves:1.33.0
sshd:3.1.0
stashNotifier:1.20
structs:1.23
terraform:1.0.10
token-macro:266.v44a80cf277fd
trilead-api:1.0.13
variant:1.4
workflow-aggregator:2.6
workflow-api:2.46
workflow-basic-steps:2.24
workflow-cps:2.94
workflow-cps-global-lib:2.21
workflow-durable-task-step:2.40
workflow-job:2.41
workflow-multibranch:2.26
workflow-scm-step:2.13
workflow-step-api:2.24
workflow-support:3.8
Linux
  1. Set up a build plan as per @aukevanleeuwen 's comment https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/481#issuecomment-916090144. This will trigger builds on all commits to master and develop, and any other branch when there's a PR.

Results

Expected result: When pushing to a branch other than develop/master (in other words another branch with a PR), I was hoping the plug-in would set CHANGE_AUTHOR and CHANGE_AUTHOR_EMAIL to the author of the latest push which triggered the build. The person who triggered the change appears correctly in the Jenkins UI (both blueocean and the classic UI).

Actual result:

The creator of the PR is used as the CHANGE_AUTHOR and CHANGE_AUTHOR_EMAIL instead.

KalleOlaviNiemitalo commented 3 years ago

This is by design; see https://github.com/jenkinsci/branch-api-plugin/blob/c520eb2c5c5e9071129a1afa251b5a9ebb9a69ce/src/main/resources/jenkins/branch/BranchNameContributor/buildEnv.properties https://github.com/jenkinsci/branch-api-plugin/blob/c520eb2c5c5e9071129a1afa251b5a9ebb9a69ce/src/main/java/jenkins/branch/BranchNameContributor.java

KalleOlaviNiemitalo commented 3 years ago

If you need the author of the commit, perhaps you can get it by running git log -1 --format="%an <%ae>" and capturing the output. Except this will use the merge commit if Jenkins is building the result of merging the pull request.

If you instead need the person who pushed to the source branch of the pull request, then that's https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/413.