jenkinsci / gitlab-branch-source-plugin

A Jenkins Plugin for GitLab Multibranch Pipeline jobs and Folder Organization
https://plugins.jenkins.io/gitlab-branch-source
MIT License
123 stars 93 forks source link

Plugin doesn't populate credentials drop down #110

Open JordanRoss1992 opened 3 years ago

JordanRoss1992 commented 3 years ago

When configuring GitLab Servers in the Jenkins global configuration, the credentials dropdown doesn't populate with system credentials.

We have a private GitLab server on the same network as our Cloudbees instance. After entering the GitLab URL in the URL field, the UI shows an "Invalid GitLab Server URL".

I did some digging into the source code and figured out that it tries to hit the /projects API of the gitlab instance in order to validate the location. For our instance, you can't hit the /projects API unless you're authorized. Since the credentials drop down seemingly doesn't populate unless you've entered a "valid" gitlab URL (or maybe not at all?), we can't select creds to authorize the GitLab validity check with.

Also, adding new credentials from this configuration doesn't populate the drop down, but it does at them to the list of system credentials for the Jenkins managed master.

Screen shot below:

Screen Shot 2021-01-12 at 7 42 28 AM

DJViking commented 3 years ago

We have the same problem in our Jenkins LTS 2.277.1 The Credentials list is not populated. We even have a GitLab API Token Credentials there.

Though we do not get that error message when entering the URL to our GitLab instance.

DJViking commented 3 years ago

I came across this issue https://github.com/jenkinsci/gitlab-branch-source-plugin/issues/107

Seems the GitLab API Token is for GitLab Plugin and cannot be used for GitLab Branch Source Plugin. Creating a new GitLab Personal Access Token Credentials is the solution here.

basyskom-hlei commented 3 years ago

I solved this by creating a GitLab API Token and NOT the GitLab Personal Update Token.

The created API Token credential shows up in the Credentials drop down menu.

robslabarbera commented 3 years ago

Wonder what I'm doing differently - I tried adding credentials both in System Configuration and Credentials Configuration - have added both Gitlab API tokens and Gitlab personal access tokens.

I still do not get anything in the "Credentials" dropdown when trying to configure the plugin.. only shows "-none-".

Credentials plugin is fully updated - 2.5 Gitlab Branch source plugin fully updated - 1.5.8

Does anyone have a step-by-step solution that worked for them, that was experiencing this same issue?

teodor20 commented 3 years ago

I am experiencing the same problem. Has anyone found a solution?

robslabarbera commented 3 years ago

@teodor20 the workaround mentioned by @basyskom-hlei failed for you as well, yes?

teodor20 commented 3 years ago

@robslabarbera The only solution that works for me is creating GitLab Personal Access Token Credentials, same as what @DJViking did.

Creating GitLab API Token does not work (it never shows up in the dropdown). None of the other credentials added to Jenkins show up either. We already have a GitLab token used for the GitLab plugin and I was hoping to use it for this plugin as well.

ajpieri commented 1 year ago

@teodor20 and @DJViking Can you give exact steps you took to achieve this? I have tried both of these and neither worked. For the GitLab Personal Access Token Credentials, this is what I did.

  1. In my GitLab project, I went to Settigns -> Access Tokens
  2. Entered a Token name
  3. Removed the Expiration date
  4. For Select a role, I selected Owner. I also tried Maintainer
  5. Selected api for the Select scopes
  6. Clicked Create project access toekn
  7. Copied the generated token it gave me for later use
  8. In my teams folder, I click New Item
  9. Then enter a name, and select Multibranch Pipeline
  10. It ends up in the Configuration for the new multibranch pipeline, and in the Branch Sources section, I select Add source -> GitLab Project
  11. I enter my gitlab's url (only the url to the server, not a specific group or project)
  12. Now, I get a list of credentials, but nothing I have added. I click the Add and select Jenkins
  1. This brings up the Jenkins Credentials Provider. For Kind I select GitLab Personal Access Token
  2. In the Token field, I put my token
  3. I give it an ID and description and click Add
  4. It takes me back to my multibranch pipeline's configuration page, and the newly added credentials are not in the drop down
  5. now...I did go into Manage Jenkins -> Credentials and added them there as well. If I go to System and find the Gitlab Server that I added, I can find my credentials there, and clicking Test Connection works. However, the credentials never show up for my individual Pipelines