Is it possible to have the upstream build trigger to include the branch details?

Jenkins Version: Jenkins 2.401.3
Hello, My upstream build trigger works with below statement in my downstream JenkinsFile.
upstream(upstreamProjects: “MyUpstreamProject”, threshold: hudson.model.Result.SUCCESS)

Build triggered for all the branches, though I want to run the downstream project only for the main branch. Tried specifying the branch as

upstream(upstreamProjects: “MyUpstreamProject/main”, threshold: hudson.model.Result.SUCCESS)
upstream(upstreamProjects: “MyUpstreamProject/refs
%2Fremotes%2Forigin%2Fmain”, threshold: hudson.model.Result.SUCCESS)

But both options did not work, any suggestions?

Since the upstream task appears in every branch, then you’ll either need to remove it from those branches or move the invocation into the upstream job so that it invokes exactly the target job that you want to run. Instead of using upstream, you’ll need to use build to call from upstream to downstream.

Than you Mark Waite. I will try the options.