I did some debugging of the JS frontend on a fresh Jenkins v2.426 with the Bitbucket Branch Source plugin 848.v42c6a_317eda_e. In the global settings I have the Bitbucket Cloud Endpoint.
If I understand correctly, here is the expected sequence when adding a branch source to a Job:
- The serverUrl select is filled by a POST request to fillServerUrlItems
- When the selected value of the serverUrl select changes, all observers are notified; this includes the credentialsId select.
- The credentialsId select is updated by a POST request to fillCredentialsIdItems with the parameter serverId set to the newly selected value of the serverUrl select. This is where things go wrong because on the first request to fillCredentialsIdItems, the serverId parameter is empty. A second request with the updated server URL never happens.
The serverUrl select is filled on line 135 in jenkins/core/src/main/resources/lib/form/select/select.js at master · jenkinsci/jenkins (github.com) by calling updateListBox:
updateListBox(e, e.getAttribute("fillUrl"), {
parameters: params,
onSuccess: function () {
if (value == "") {
var v = e.getAttribute("value");
if (v) {
e.value = v;
if (e.value == v) {
e.removeAttribute("value");
}
}
}
fireEvent(e, "filled");
if (hasChanged(e, value)) {
fireEvent(e, "change");
}
},
});
This leads to a POST request to fillServerUrlItems which returns the value "https://bitbucket.org" as expected.
In the onSuccess callback we conditionally fire the "change" event which would in turn trigger a refill of the credentialsId select. The problem is that hasChanged returns false for an initial fill so the credentialsId select is never updated with the new server URL.
Unfortunately I'm not sure how to fix this. There is likely a good reason for not considering the initial fill of a select as a "change" so I would not touch the implementation of hasChanged. Maybe the credentialsId select should observe the "fill" event in addition to the "change" event although I don't know how one would implement this.
It seems like the dependency of the credentialsId select to the serverUrl select is declared in the HTML select tag:
<select checkdependson="serverUrl" fillurl="/job/test/descriptorByName/com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource/fillCredentialsIdItems" checkurl="/job/test/descriptorByName/com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource/checkCredentialsId" filldependson="serverUrl" name="_.credentialsId" class="jenkins-select__input validated select credentials-select" value=""><option value="">- none -</option></select>
Note the filldependson="serverUrl".
Hopefully someone with more front-end experience than me (> 0) can figure this out :^)
This is related to https://github.com/jenkinsci/bitbucket-branch-source-plugin/issues/706
It seems as "Secret text" credentials are not included in the creds list for Bitbucket Cloud instances. But even if in my case I'm selecting a Bitbucket Server instance, the initial configuration page seems to handle it as a cloud instance and thus not showing the "Secret text" credential. But when editing an existing multibranch-pipeline it seems to handle it correctly as a Server instance and therefore shows the "Secret text" credential.