I'm debugging a problem with atlassian-bitbucket-server-integration-plugin. The behavior occurs when generating a multi-branch pipeline job, which requires a Bitbucket webhook. The plugin works fine when creating the pipeline job from the Jenkins UI. However, when using DSL to create an equivalent job, the plugin errors out attempting to create the webhook.
I've tracked this down to a line in RetryingWebhookHandler
:
String jenkinsUrl = jenkinsProvider.get().getRootUrl();
if (isBlank(jenkinsUrl)) {
throw new IllegalArgumentException("Invalid Jenkins base url. Actual - " + jenkinsUrl);
}
The jenkinsUrl
is used as the target for the webhook. When the pipeline job is created from the UI, the jenkinsUrl
is set as expected. When the pipeline job is created by my DSL in a freeform job, the jenkinsUrl
is always null
. As a result, the webhook can't be created and the job fails.
I've tried various alternative ways to get the Jenkins root URL, such as static references like Jenkins.get().getRootUrl()
and JenkinsLocationConfiguration.get().getUrl()
. However, all values come up empty. It seems like the Jenkins context is not available at this point.
I'd like to submit a PR to fix this behavior in the plugin, but I can't come up with anything workable. I am looking for suggestions about the root cause and potential workarounds. For instance:
- Is there something specific about the way my freeform job is executed that could cause this?
- Is there anything specific to the way jobs are generated from DSL that could cause this?
- Is there another mechanism I should be looking at to get the root URL from configuration, which might work better?
- Is it possible that this behavior points to a misconfiguration in my Jenkins instance?
If needed, I can share the DSL I'm using to generate the job, but I don't think it's relevant. By commenting out the webhook code that fails, I've confirmed that the DSL generates a job with the correct config.xml
underneath. So, the only problem is how to get the right configuration to the plugin so it can set up the webhook.
question from:
https://stackoverflow.com/questions/65947423/why-is-jenkins-get-getrooturl-not-available-when-generating-dsl 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…