Skip to content

Environment variable RJPP_BRANCH is initialized with wrong value #127

@NitzKo95

Description

@NitzKo95

Describe the bug
Environment variable RJPP_BRANCH is initialized with wrong value when setting multiple values in 'Branches to build' section (image attached)

To Reproduce
Steps to reproduce the behavior:

Consider the following git branch tree:

*-----*-----* (master)
 \
  *-----*-----*-----* (feature1)
  1. Create new Multibranch Pipeline
  2. Define the 'Mode' in 'Build Configuration' to by Remote Jenkinsfile Provider Plugin
  3. Configure script path - Pipeline should include a sh step to print env vars as follows
    sh "printenv RJPP_BRANCH"
  4. Set 'Jenkinsfile SCM settings' to Git
  5. Add multiple existing branches to 'Branches to build', master being the first
    5.a. Note the order of configured branches matters - make sure the first configured branch's HEAD isn't committed last
  6. Finish configuration according to your settings
  7. Submit & Scan Job
  8. Run the pipeline in any of the scanned branches
  9. The pipeline runs, reading (remotely) Jenkinsfile from the most-recently-committed branch HEAD
  10. View Console Output, see 1st occurrence of 'Checking out Revision': (related to JRPP)
    10.a. Commit ID selected is the most recent commit, as expected
  11. See printenv step output:
    11.a. Printed RJPP_BRANCH value matches the 1st element configured in 'Branches to build' (master according to the git tree provided above), regardless if it was checked-out or not.

Expected behavior
RJPP_BRANCH value should match the actually checked-out Jenkinsfile branch.

Screenshots
Screenshot 2022-11-20 at 15 06 17

Desktop (please complete the following information):
IMO irrelevant, running on cloud VM as Docker container, image pulled from DockerHub

Extra Info:
In the attached image, until I moved the REDACTED branch to the top of the list, '*/master' was printed as JRPP_BRANCH's value.
I'm trying to define some logic based on the branch used for reading the Jenkinsfile, so the current statue forces me to reorder the list for every development I need to make on the given pipeline, rather just adding a development branch to the list 'knowing' it'll be used and initialize JRPP_BRANCH, and remove it when done.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions