Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variable RJPP_BRANCH is initialized with wrong value #127

Open
NitzKo95 opened this issue Nov 20, 2022 · 1 comment
Open

Environment variable RJPP_BRANCH is initialized with wrong value #127

NitzKo95 opened this issue Nov 20, 2022 · 1 comment

Comments

@NitzKo95
Copy link

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.

@aytuncbeken
Copy link
Contributor

Hi @NitzKo95

I have checked the implementation. You are right, JRPP_BRANCH is always showing the first value is set on the configuration. Unfortunately, this is not something that this plugin solve. Here are the details.

When Jenkins tries to reach to Jenkinsfile, this plugin interferes and says Jenkins to use the Git SCM definition which is defined under the "Remote Jenkins File Provider" Section. Then Jenkins, get this config and passes to the underlying Git plugin which handles all the checkout actions. Unfortunately, it is not possible to interfere that checkout action or get info about it.

I will keep this open and check in 6 months.

Thanks for reporting this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants