CloudBees action: Configure Git global credentials

3 minute read

Use this action to set up a Git global configuration for use in CloudBees workflows. This action authenticates the current user, by default scoped to repositories in the same organization as the workflow repository. After this step is run, all steps using the Git CLI in the same job authenticate with these credentials.

Use this action to avoid failures caused by lack of pre-authentication of private repositories. For example, if you are building a Go module that depends on other private modules, private repository authentication must be in place for go mod download to run successfully.

This action may set up authentication for different types of Git global configurations, including:

If you use a Git client other than the official Git CLI, ensure that your client supports the authentication configuration applied by this action.

All CloudBees action repositories are listed at CloudBees, Inc. on GitHub.

Inputs

Table 1. Input details
Input name Data type Required? Description

repositories

String

Yes

Repository clone URL https://github.com/user/repo.

To list multiple repositories, CloudBees recommends using a line break separator, although the repositories parameter accepts a whitespace- or comma-separated list.

ssh-key

String

No

SSH key used to fetch the repository using its SSH clone URL (passed via the repositories input). Only relevant when you define an SSH clone URL via the repositories input. In all other cases, the action fetches the pre-configured credentials set up on CloudBees Unify for the specified repositories.

ssh-known-hosts

String

No

A list of known SSH hosts that should be added to the global host database. Use the utility ssh-keyscan to get public SSH keys for a host.

The public keys for GitHub and Bitbucket are added by default.

ssh-strict

Boolean

No

Default is true. When true, performs strict host key checking, by adding the options StrictHostKeyChecking=yes and CheckHostIP=no to the SSH command line. Use the input ssh-known-hosts to configure additional hosts.

Usage examples

The following examples show how to configure access to repositories using different methods.

Multiple repositories using a specific integration

In your YAML file, add:

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: | https://github.com/user1/repo https://github.com/user2/rep1

For configuring access for all repositories within a GitHub project/user namespace, specify the Project URL as an input: https://github.com/org/

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: https://github.com/org/

Alternatively, specify a host URL in the repositories input to grant access to all accessible repositories. This is dependent on the SCM integration and the credentials and permissions configured for those credentials, which are set up on CloudBees Unify for this component and its parent organizations.

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: https://github.beescloud.com/

Multiple Bitbucket repositories using a workspace access token

If you have a Bitbucket Workspace access token configured in your SCM integration, you can grant access to all repositories in a workspace by specifying the workspace URL:

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: https://bitbucket.org/my-workspace/

Alternatively, specify individual Bitbucket repositories:

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: | https://bitbucket.org/my-workspace/repo-one https://bitbucket.org/my-workspace/repo-two

For more information about Bitbucket token types and which scopes are required, refer to Bitbucket access tokens.

SSH key configuration for repository access

When defining the SSH key secret, ensure the secret ends with a new line.

In your YAML file, add:

- name: Git global credentials uses: cloudbees-io/configure-git-global-credentials@v2 with: repositories: "ssh://github.com/user/repo" ssh-key: ${{secrets.<ssh-secret-name-placeholder>}}