When reporting a Pull Request to SeaLights, the parameters required to configure the pull request BSID vary between the source control provider.
This article will help you to map the required parameters to their location within the few most common source control or CI providers:
Here is a table summarizing the most common variables in use, details below in the relevant SCM section
Sealights PR Parameter | Jenkins GitHub Pull Request Builder variables | BitBucket env. variables | GitLab env. variables | Generic Git variables |
---|---|---|---|---|
pullRequestNumber | ghprbPullId | BITBUCKET_PR_ID | CI_EXTERNAL_PULL_REQUEST_IID | GIT_PULL_REQUEST |
latestCommit | ghprbActualCommit | BITBUCKET_COMMIT | CI_COMMIT_SHA | GIT_COMMIT |
repoUrl | ghprbPullLink | BITBUCKET_REPO_SLUG or BITBUCKET_GIT_HTTP_ORIGIN | CI_REPOSITORY_URL | GIT_REPO_URL |
targetBranch | ghprbTargetBranch | BITBUCKET_PR_DESTINATION_BRANCH | CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME | CHANGE_TARGET |
For latestCommit parameter, we’re highlighting the short version in the screenshots below but the long/entire SHA identifier needs to be used.
GitHub
If you’re using the GitHub Pull Request Builder you can use the following mapping to environment variables provided by the plugin
Sealights PR Parameter | GitHub Pull Request Builder variables | Comment |
pullRequestNumber | ghprbPullId | |
latestCommit | ghprbActualCommit | |
repoUrl | ghprbPullLink | Something similar to: https://github.mycompany.com/myappjava/ if the pull request URL is |
targetBranch | ghprbTargetBranch | This is the branch name itself and might need to have a prefix added (Like: "origin/") to match the branch that was provided to SeaLights when scanning the merged branch |
GitLab
Please notice GitLab refers to this capability as Merge Request (MR) and not as Pull Request (See GitLab documentation for more details).
Then, switching to the “Commits” tab:
More details for GitLab may be found in the official documentation: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
Using the GitLab plugin for Jenkins
If you’re using the GitLab plugin for Jenkins you can use the following mapping to environment variables provided by the plugin
Sealights PR Parameter | GitLab plugin variables | Comment |
pullRequestNumber |
| |
latestCommit |
| |
repoUrl |
| |
targetBranch |
| This is the branch name itself and might need to have a prefix added (Like: "origin/") to match the branch that was provided to SeaLights when scanning the target branch |
More details about available variables from this plugin may be found in the official documentation: https://github.com/jenkinsci/gitlab-plugin#defined-variables
BitBucket
Bitbucket provides a set of default variables that are available for builds, and can be used in scripts. These variables are detailed in the official Bitbucket documentation and can be used like below
Sealights PR Parameter | BitBucket Env. Variable | Comment |
---|---|---|
pullRequestNumber | BITBUCKET_PR_ID | |
latestCommit | BITBUCKET_COMMIT | |
repoUrl | BITBUCKET_REPO_SLUG | In some configurations, you may need to prepend the base URL of your repository, like "https://bitbucket.mycompany.int/$BITBUCKET_REPO_SLUG" |
targetBranch | BITBUCKET_PR_DESTINATION_BRANCH | This is the branch name itself and might need to have a prefix added (Like: "origin/") to match the branch that was provided to SeaLights when scanning the merged branch |
Using Webhook to Jenkins for Bitbucket plugin (sending URL parameters to Jenkins)
Pull Request related variables (e.g. Pull Request number) can be passed from Bitbucket to a Jenkins job via the Webhook to Jenkins for Bitbucket plugin using URL parameters to be defined in the plugin settings.
In the example below, the Bitbucket Pull Request ID number (parameter PR_ID
) is being passed via the PR_NUM
variable name and this variable will then be available as a parameter within the Jenkins job. Each URL parameter to be passed should be placed on a separate line in the URL parameters box.
Documentation for the above plugin settings is available here https://mohamicorp.atlassian.net/wiki/spaces/DOC/pages/210305025/Sending+URL+Parameters+to+Jenkins#Available-Parameters
Bamboo
Sealights PR Parameter | Bamboo Build env. variables | Comment |
pullRequestNumber | ||
latestCommit | bamboo.repository.pr.key | |
repoUrl | bamboo.planRepository.<position>.repositoryUrl | |
targetBranch | bamboo.repository.pr.targetBranch | The base reference name of the webhook event that triggered the build. It is the branch reference for pull requests (i.e. target branch). |
More details for Bamboo CI may be found in the official documentation: https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html
AWS CodeBuild
Sealights PR Parameter | AWS Code Build env. variables | Comment |
pullRequestNumber | CODEBUILD_WEBHOOK_TRIGGER | For builds triggered by a pull request, its format is |
latestCommit | CODEBUILD_RESOLVED_SOURCE_VERSION | |
repoUrl | CODEBUILD_SOURCE_REPO_URL | |
targetBranch | CODEBUILD_WEBHOOK_BASE_REF | The base reference name of the webhook event that triggered the build. It is the branch reference for pull requests (i.e. target branch). |
More details for AWS CodeBuild may be found in the official documentation: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html