Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Secret text" Git credentials not showing up in Jenkins project Source Code Management section

I am unable to see any Secret text credentials in the drop down in my Jenkins' project SCM section. I know that creating a Secret text credential from the drop down in SCM section is broken, but even if I create the credential by navigating to Jenkins -> Credentials, that credential does not appear in the drop down.

I've created every type of credential and the only type I see in the dropdown is Username with password. It seems like the dropdown in SCM filters out every credential that is not of this type.

The reason I need Secret text credentials in the SCM section is because I want to use a Github access token (and not my Github account username and password).

The following screenshot shows my global credentials where my Secret text credential is clearly present. Global credentials with Secret text credential present

The following screenshot shows my project's SCM section's Git dropdown where only the Username and password credential is present.Git SCM section with no Secret text credential present

Jenkins version: 2.102
Jenkins Credentials plugin version: 2.1.16
Jenkins Git plugin version: 3.7.0

like image 984
Scott Storch Avatar asked Jan 18 '18 21:01

Scott Storch


People also ask

Why credentials are not showing in Jenkins?

2 Answers. Show activity on this post. Show activity on this post. Manage Jenkins > Manage Plugins > Click on available > enter credentials.

How do I add secret credentials in Jenkins?

From the Jenkins home page (i.e. the Dashboard of the Jenkins classic UI), click Manage Jenkins > Manage Credentials. Under Stores scoped to Jenkins on the right, click on Jenkins. Under System, click the Global credentials (unrestricted) link to access this default domain. Click Add Credentials on the left.


2 Answers

You can't use the Secret Text credential for the SCM step because the Github Personal Access Token is only supposed to replace your password. Not your user and password. Meaning your user is still required. In the Github documentation here you'll see it reads:

You can create a personal access token and use it in place of a password

And then below in section "Using a token on the command line" here it reads:

Once you have a token, you can enter it instead of your password when performing Git operations over HTTPS.

And it follows up with this example:

$ git clone https://github.com/username/repo.git
Username: your_username
Password: your_token

If you extrapolate this to Jenkins, the sensible choice of credential type is still the User with password one.

So, simply create a credential of type User with password as you normally would and use your personal access token for the Password field.

User with password credential using personal access token instead

like image 117
Mig82 Avatar answered Oct 30 '22 00:10

Mig82


After installing the Credentials Bindings plugin, the Build Environment section of your build job Configuration page will include a new option to “Use secret text(s) or file(s)”. Enabling this option allows you add credential bindings where the Variable value will be used as the name of the environment variable that your build can use to access the value of the credential.

For example you create a secret: (the ***** = 12345) enter image description here

You can use it in the following way in your build: enter image description here

Output of echo $VAR in my case is *****. But you can use it as 12345 in your job. This is how you use secret text. The name says it all. The text remains secret but you can use it as unprinted variable in your job. This is for text, not for credentials.

If you want to reuse your credentials in your build it's recommended to use the "username and password conjoined". Here you can set a variable for your credentials. More info can be found here on how you can split username and password.

like image 34
lvthillo Avatar answered Oct 30 '22 00:10

lvthillo