bitbucket plugin - JENKINS-65697 - How to inject environment variable into WorkflowMultiBranchProject (buildEnvironment isn't called...)

145 views
Skip to first unread message

tzach solomon

unread,
Jul 24, 2023, 1:58:54 AM7/24/23
to jenkin...@googlegroups.com
Hi All,

Sorry for the long title but I'm really at lost here... 

I'm the maintainer of the bitbucket plugin and I would like to solve JENKINS-65697.
I've checked the code and it looks like the triggered job is of class WorkflowMultiBranchProject. The future job I'm getting once scheduled OK is jenkins.branch.MultiBranchProject$BranchIndexing.

I've tried to inject environment variables into it by using the already existing class BitBucketPayload which looks like this BitBucketPayload extends InvisibleAction implements EnvironmentContributingAction

My problem is that the buildEnvironment method isn't called.

What am I doing wrong?

Thanks in advance,
Tzach

Jesse Glick

unread,
Jul 24, 2023, 9:25:49 AM7/24/23
to jenkin...@googlegroups.com
On Mon, Jul 24, 2023 at 1:58 AM tzach solomon <tzach....@gmail.com> wrote:
I've checked the code and it looks like the triggered job is of class WorkflowMultiBranchProject. The future job I'm getting once scheduled OK is jenkins.branch.MultiBranchProject$BranchIndexing.

I've tried to inject environment variables into it by using the already existing class BitBucketPayload which looks like this BitBucketPayload extends InvisibleAction implements EnvironmentContributingAction

My problem is that the buildEnvironment method isn't called.

Nor should it be. That is an extension point for builds. You are discussing branch indexing. Maybe you are looking in the wrong place.

tzach solomon

unread,
Jul 25, 2023, 2:24:57 AM7/25/23
to jenkin...@googlegroups.com
Thanks Jesse for the quick response.

Is there a guide to understand how I can get build from the Queue Item I have?

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1d4PqcO4LGmFrOhw%2B73DypfCvJE65QeMt9OMr4rKQ2ow%40mail.gmail.com.

Jesse Glick

unread,
Jul 25, 2023, 5:27:20 PM7/25/23
to jenkin...@googlegroups.com
On Tue, Jul 25, 2023 at 2:24 AM tzach solomon <tzach....@gmail.com> wrote:
get build from the Queue Item

I am not sure what that means. You are going to need to be more specific, preferably with code references, ideally a JenkinsRule-based test failing in the “right” way.

tzach solomon

unread,
Aug 10, 2024, 8:32:11 AM8/10/24
to jenkin...@googlegroups.com
Reviving this old thread as I got a bit of time to try to fix this bug... (Can you please help approve/disapprove my comment below?)

I've tried to figure out why `buildEnvironment` is not called and it's because when scheduling a `WorkflowMultiBranchProject` (using schedule2) with my Actions, those actions will be ignored since the branch will always be triggered with 
source.fetch(new SCMHeadObserverImpl(source, observer, listener, _factory, new IndexingCauseFactory(), null), listener);

And that is why the console always has 'Branch indexing' and not my cause.

Is that correct?

Thanks,
Tzach

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

tzach....@gmail.com

unread,
Aug 10, 2024, 3:58:43 PM8/10/24
to Jenkins Developers
I think I've got it.
I should have used EnvironmentContributor.java as used in https://github.com/jenkinsci/branch-api-plugin/blob/master/src/main/java/jenkins/branch/BranchNameContributor.java#L56

An I right?

if so, what is the difference between 'EnvironmentContributor.java' and 'EnvironmentContributingAction.java'?
When should I use  EnvironmentContributor and when should I use EnvironmentContributingAction?

Thanks in advance,
Tzach

tzach solomon

unread,
Aug 10, 2024, 4:03:01 PM8/10/24
to jenkin...@googlegroups.com

Jesse Glick

unread,
Aug 12, 2024, 7:23:10 AM8/12/24
to jenkin...@googlegroups.com
On Sat, Aug 10, 2024 at 8:32 AM tzach solomon <tzach....@gmail.com> wrote:
I've tried to figure out why `buildEnvironment` is not called and it's because when scheduling a `WorkflowMultiBranchProject` (using schedule2) with my Actions, those actions will be ignored since the branch will always be triggered with 
source.fetch(new SCMHeadObserverImpl(source, observer, listener, _factory, new IndexingCauseFactory(), null), listener);

And that is why the console always has 'Branch indexing' and not my cause.

There is little context here, but the queue item for a computed folder (like `WorkflowMultiBranchProject`) is unrelated to the queue item for a branch project child (`WorkflowJob`). If you wish to affect the latter, `EnvironmentContributor` is one option.

tzach solomon

unread,
Aug 12, 2024, 7:45:58 AM8/12/24
to jenkin...@googlegroups.com
Thanks Jesse! :) 
What is another option? Just so I'll know for next time :) 

--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

Jesse Glick

unread,
Aug 12, 2024, 12:02:57 PM8/12/24
to jenkin...@googlegroups.com
On Mon, Aug 12, 2024 at 7:45 AM tzach solomon <tzach....@gmail.com> wrote:
What is another option?

There is no other option if you simply wish to inject some environment variables at top level in a build, knowing nothing about the Pipeline being run. 
Reply all
Reply to author
Forward
0 new messages