Source Control Configuration

NEW IN RELEASE 79

Setting up Nexus IQ for SCM

Configure the IQ Server Base URL

SCM features will not work unless the IQ Server Base URL is configured.

Required Token Permissions

FeatureGitHubBitbucket ServerBitbucket CloudGitLab
Automated Commit Feedbackrepo:statusRead under RepositoriesRead under Repositories

api

Automated Pull RequestsrepoWrite under RepositoriesWrite under Pull Requests
(error)
Pull Request CommentingrepoWrite under Repositories(error)(error)
Pull Request Line CommentingrepoWrite under Repositories(error)(error)
Bitbucket Code InsightsN/AWrite under Repositories(error)N/A

Steps to Use SCM Features

The steps required to enable automated pull requests (supported in GitHub, Bitbucket Server, and Bitbucket Cloud) and automated commit feedback (supported in GitHub, GitLab, Bitbucket Server, and Bitbucket Cloud) are as follows:

Create an access token for your source control management (SCM) system

GitHub

In GitHub create a personal access token:

  1. Log in to GitHub.
  2. In the upper-right corner click your avatar and select Settings.
  3. In the left menu click Developer Settings.
  4. In the left menu click Personal access tokens.
  5. Click the Generate new token button.
  6. Save the personal access token somewhere safe for later use as once you leave the generate token dialog you will not be able to view it again.

See this explanation for details of GitHub scopes.

GitLab

The automated pull request feature is not yet supported for GitLab

In GitLab, create a personal access token:

  1. Log in to GitLab.
  2. In the upper-right corner click your avatar and select Settings.
  3. On the User Settings menu select Access Tokens.
  4. Choose a name and optional expiry date for the token.
  5. Click the Create personal access token button.
  6. Save the personal access token somewhere safe. Once you leave or refresh the page you won’t be able to access it again.

Bitbucket Server

  1. Log into Bitbucket Server.
  2. In the top right click your avatar and choose Manage Account.
  3. In the left menu choose Personal access tokens.
  4. Click the Create a token button.
  5. Choose a name for the token.
  6. Click Create.
  7. Save the personal access token somewhere safe. Once you leave or refresh the page you won’t be able to access it again.
  8. Note that for Bitbucket Server the username for the account is also required.

See this article for more information on Bitbucket Server Personal Access Tokens.

Bitbucket Cloud

  1. Log into Bitbucket Cloud.
  2. In the bottom left click your avatar and choose Bitbucket settings.
  3. In the Settings menu choose App passwords.
  4. Click the Create app password button.
  5. Choose a label for the token.
  6. Click Create.
  7. Save the app password somewhere safe. Once you leave or refresh the page you won’t be able to access it again.
  8. Note that for Bitbucket Cloud the username for the account is also required.

See this article for more information on Bitbucket Cloud App passwords.

Inform IQ Server about your Source Control Configuration

Enter your Root Organization Source Control Configuration

  1. Login to Nexus IQ Server.
  2. Navigate to the Root Organization.
  3. Navigate to the Source Control configuration section.
  4. Click to open the Source Control Configuration edit page.
  5. Select your Access Token Provider.
  6. Optional Enter your access token. This will be used as the default access token for all organizations if entered here.
    1.  Enter the username for the token if required by your specific SCM choice.
  7. Enable or disable automated Pull Requests.
  8. Enter your Default Branch (defaults to master)

Access tokens, username, enabling automated pull requests and the default branch can be overridden at the child organization and application levels.

Optional - Organization Source Control Configuration

Organizations may have their own default credentials, enable automated pull request setting, and default branch by overriding these values at the organization level.

When a policy evaluation request comes in for any IQ application in that same organization, Nexus IQ for SCM will use the specified access token to communicate status information back to your repository.

Application Source Control Configuration

Applications may have their own credentials, enable pull request setting and default branch by overriding these values at the application level.

Applications must specify a Repository URL to receive automated commit feedback and automated pull requests. The Repository URL is entered manually here.

Valid HTTP(S) and SSH repository URLs are accepted. Two formats are supported for SSH URLsssh://user@server/project-path.git and user@server:project-path.git.

On save all SSH URLs are converted to the HTTPS format and the Repository URL will show the converted value.

Full support for SSH URLs is coming soon. Note that Bitbucket Server currenly only supports HTTP(S) URLs at this time.


With Automatic SCM Configuration turned on, the repository URL will be automatically discovered from the git project information and configured for the IQ application. Automatic SCM Configuration can be enabled via the configuration menu  on the toolbar.

Run a policy evaluation

Policy evaluations can originate from your CI environment, such as Jenkins, utilizing the IQ CLI directly or one of the Nexus IQ plugins provided for your respective CI system.  See this page for more information: https://help.sonatype.com/integrations/nexus-and-continuous-integration

You can also run a policy evaluation using the Nexus IQ command line interface (CLI) directly, as described here: https://help.sonatype.com/integrations/nexus-iq-cli

The Nexus IQ client tooling will determine the commit hash and repository details for the given build and include that information in the policy evaluation request sent to IQ server.

In order to automatically configure applications for source control integration, the Automatic Source Control Configuration system preference must be enabled and the user initiating the policy evaluation (could be a special user created to represent a CI system) must have the Evaluate Applications permission for the target application.

More details about how to enable Automatic Source Control Configuration can be found here.

Protecting the Target Branch

In some source control systems the target branch can be protected from merges with a failing IQ Policy Evaluation as described in the appropriate section below for your SCM system.

Protecting the Target Branch in GitHub

The target branch can be protected from merges with a failing IQ Policy Evaluation by configuring a branch protection rule in the repository's settings under Branches.

In the branch protection rule add a new rule or edit an existing rule.  Next, check Require status checks to pass before merging.  Finally, check IQ Policy Evaluation.

The IQ Policy Evaluation status check will not appear in the list of status checks found in the last week for this repository until the first policy evaluation status has been added to the repository.

See this page for more information: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks

Protecting the Target Branch in GitLab

GitLab projects can be configured to prevent merge requests from being merged if their pipeline did not succeed.  A failing IQ policy evaluation will cause the pipeline to fail, which in turn will prevent the merge request from being able to be merged.  You can enable this feature via the project settings as shown below.  See this page for more information:  https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html#only-allow-merge-requests-to-be-merged-if-the-pipeline-succeeds



Protecting the Target Branch in Bitbucket Server

The target branch can be protected from merges with a failing IQ Policy Evaluation by configuring a Merge check. Merge checks are a repository-wide setting and can also be enforced for all repositories.


Click the drop-down next to Minimum successful builds and choose Enabled. In the next dialog choose the desired minimum number of successful builds.

See this page for more information: https://confluence.atlassian.com/bitbucketserver/checks-for-merging-pull-requests-776640039.html

Protecting the Target Branch in Bitbucket Cloud

Bitbucket Cloud has two options for protecting the target branches from merges with a failing IQ Policy Evaluation.

  1. For all accounts, users get notified when they don't have that number of successful builds for the most recent commit.
  2. For premium accounts, users won't be able to merge if their pull request has unresolved merge checks

Click Settings, then Branch permissions, then Add a branch permission.

In the Add a branch permission dialog, select the desired branch option as well as the desired write access and merge access. In the Merge checks section select the option Check the last commit for at least 1 successful build and no failed builds.

This will inform users that the requirements are not fulfilled when trying to merge, but it will not prevent the merge.



Premium accounts have the additional ability to prevent the merge.

This will prevent users from merging a pull request with a failed build.


See these pages for more information: