Creating organizations in Snyk
This page has instructions for creating organizations (Orgs) in Snyk:
Generating the data to create organizations in Snyk
Before an import can begin you must set up Snyk with the organizations you will populate with projects.
It is recommended to have as many organizations in Snyk as you have in the source you are importing from. For GitHub this means mirroring the GitHub organizations in Snyk. The snyk-api-import
tool provides a utility to use to make this simpler when using Groups and Organizations in Snyk.
Generating the data required to create organizations in Snyk with orgs:data
util
orgs:data
utilThis util helps generate data needed to mirror the GitHub.com, GitHub Enterprise, GitLab, Bitbucket Server, or Bitbucket Cloud organization structure in Snyk. This is an opinionated util and will assume every organization in GitHub.com, GitHub Enterprise, GitLab, Bitbucket Server, or Bitbucket Cloud should become an organization in Snyk. If this is not what you are looking for, consider using the Organizations API directly to create the structure you need.
Options
GitHub.com and GitHub Enterprise
set the GitHub.com personal access token as an environment variable:
export GITHUB_TOKEN=your_personal_access_token
Run the command to generate organization data:
GitHub.com:
snyk-api-import orgs:data --source=github --groupId=<snyk_group_id>
GitHub Enterprise:
snyk-api-import orgs:data --source=github-enterprise --groupId=<snyk_group_id> -- sourceUrl=https://ghe.custom.github.com/
This creates the organization data in a file group-<snyk_group_id>-github-<com|enterprise>-orgs.json
GitLab.com and Hosted GitLab
set the GitLab personal access token as an environment variable:
export GITLAB_TOKEN=your_personal_access_token
Run the command to generate organization data:
GitLab:
snyk-api-import orgs:data --source=gitlab --groupId=<snyk_group_id>
Hosted GitLab:
snyk-api-import orgs:data --source=gitlab --groupId=<snyk_group_id> -- sourceUrl=https://gitlab.custom.com
This creates the organization data in a file group-<snyk_group_id>-gitlab-orgs.json
Bitbucket Server
Note that Bitbucket Server is a hosted environment and you must provide the custom URL for your Bitbucket Server instance in the command.
set the Bitbucket Server access token as an environment variable:
export BITBUCKET_SERVER_TOKEN=your_personal_access_token
Run the command to generate organization data:
snyk-api-import orgs:data --source=bitbucket-server --groupId=<snyk_group_id> --sourceUrl=https://bitbucket-server.custom.com
This creates the organization data in a file group-<snyk_group_id>-bitbucket-server-orgs.json
Bitbucket Cloud
Note that the URL for Bitbucket Cloud is https://bitbucket.org/
set the Bitbucket Cloud Username and Password as environment variables:
export BITBUCKET_CLOUD_USERNAME=your_bitbucket_cloud_username
andexport BITBUCKET_CLOUD_PASSWORD=your_bitbucket_cloud_password
Run the command to generate organization data:
snyk-api-import orgs:data --source=bitbucket-cloud --groupId=<snyk_group_id>
This creates the organization data in a file group-<snyk_group_id>-bitbucket-cloud-orgs.json
Azure
Note that for Azure, this step needs to be done manually Since Azure has no API call for getting the Azure Organizations, the Orgs file must be created manually for the next commands to run:
The file should be formatted this way:
Once the file is created, you can feed it to the orgs:create command
Methods of creating Orgs
Use the generated data file to help create the organizations via API or use the provided util.
via API
Use the generated data to feed into the Snyk Orgs API to generate the organizations within a group.
via orgs:create
util
orgs:create
utilset the
SNYK_TOKEN
environment variable - your Snyk api tokenRun the command to create Orgs:
snyk-api-import orgs:create --noDuplicateNames --includeExistingOrgsInOutput --file=group-<snyk_group_id>-github-<com|enterprise>-orgs.json
Use the
noDuplicateNames
flag (optional) to skip creating an organization if the given name is already taken within the Group.Use the
includeExistingOrgsInOutput
flag (optional, default is "true") to log information for existing organizations as well as newly created Orgs. To set this flag as false, use "--no-includeExistingOrgsInOutput" in the command as follows:snyk-api-import orgs:create --no-includeExistingOrgsInOutput --file=group-<snyk_group_id>-github-<com|enterprise>-orgs.json
The file format required for this command is as follows:
groupId
- public id of the Snyk Group where the organization is to be createdname
- name to use when creating the organizationsourceOrgId
- optional public id of a Snyk organization to copy settings from
Recommendations
Have notifications disabled for emails and so on to avoid receiving import notifications.
Have the fix PRs and PR checks disabled until import is complete to avoid sending extra requests to SCMs (GitHub, GitLab, Bitbucket, other).
Last updated