Integration with Azure DevOps

  • 17 January 2023
  • 0 replies
  • 954 views

With our CI integration to Azure DevOps you can automatically upload your latest commits and pull requests to Debricked or whenever you run your pipeline. Our Azure DevOps integration support the same options as our Bitbucket integration.

 

 

Integrate a single repository

 

Configure Debricked token

Start by generating an access tokenCopy the token so that you can use it in the next step.

Configure your DEBRICKED_TOKEN variable by heading over to [your repository] -> Pipelines -> [your pipeline name] -> Edit -> Variables. Make sure to check “Keep this value secret” so you don’t expose your login credentials to the world.


Configure Azure Pipelines

Depending on what package manager you are using there are different step setups.

In order for us to analyze all dependencies in your project, their versions, and relations, files containing the resolved dependency trees have to be created prior to scanning. Those depend on the package manager used. If files are lacking we try to generate them on our side, which can negatively affect speed and accuracy.

Example 1: If npm is used in your project you will have a package.json file, but in order for us to scan all your dependencies we need either package-lock.json or yarn.lock as well.

Example 2: If Maven is used in your project you will have a pom.xml file, but in order for us to resolve all your dependencies we need a second file, as Maven does not offer a lock file system. Instead, Maven dependency:tree plugin can be used to create a file called .debricked-maven-dependencies.tgf.

 

  1. Add the template to your azure-pipelines.yml file (if the file doesn't exist, create one).
  2. Commit your changes to azure-pipelines.yml and watch the CI run! 

 

Configure Azure Pipelines - video guide

 

Integrate multiple repositories

Integrating many repositories with one configuration using Azure DevOps can greatly simplify the process of managing and deploying code across multiple projects.

Step 1: Create a variable group

To avoid having to add the DEBRICKED_TOKEN to every integrated repository, it is possible to share the Debricked token between repositories. In order to enable this, you need to create a variable group:

  1. Generate a Debricked access token
  2. Sign in to your organisation and select your project
  3. Go to: Pipelines → Library → Variable groups
  4. Click + Variable group
  5. Enter a suitable name for your variable group, eg. "Debricked”
  6. Click on + Add
  7. Add your token from 1. to a secret variable called DEBRICKED_TOKEN (to make it secret, toggle the "lock" icon at the end of the row)
  8. Click Save
  9. Go to the Pipeline permissions tab
  10. Press three vertical dots and choose Open access to allow access in all pipelines. If you want to, it is also possible to just specify specific pipelines who should get access.
  11. After this you will be able to use the created variable in your repository pipelines.

Step 2: Create new Service connection

If you would like to use our shared template out-of-the box without modifications, you first need to create a service connection to GitHub. If you’re, however, planning on copying the main template into your own organisation you can skip this step.

  1. Go to: Project settingsService connections
  2. Click Create service connection
  3. Select Github from the list, and press Next
  4. In OAuth Configuration drop-down select AzurePipelines
  5. Press Authorize and follow instructions, using your own GitHub account
  6. Give new service connection name, which you will use as a value for endpoint parameter later on
  7. Click Save

Step 3: Use the template in pipelines of required repositories

You can now use the following template in pipelines of repositories you want to integrate with Debricked. The triggering template refers directly to the Azure DevOps template core repository found in the Debricked CLI repository. If you would like to make modifications to it, it is also possible to copy the template from the CLI repository into a core repository of your own, which you would then refer to in the triggering template below.

NOTE: During the first run of the pipeline it will ask permission to run subsequent job. You should click Permit.

Triggering template

trigger:
branches:
include:
- '*' # Run on all branches

variables:
- group: <variable_group_name>

resources:
repositories:
- repository: <repository_reference>
type: <repository_type>
name: <username_or_project>/<repository_name>
endpoint: <service_connection_name>

jobs:
- template: <resource_template_file_name>@<repository_reference>
parameters:
DEBRICKED_TOKEN: $(DEBRICKED_TOKEN)

Option 1: Directly referencing the Debricked core repository

By directly referencing the Debricked core repository, you will automatically receive any new updates made to the Debricked core repository template. If you would like to customize the template, use the setup described in option 2 below.

  1. In the repositories that you want to trigger the shared pipeline from, paste the triggering template above to an azure pipelines yaml file.
  2. Fill in the variables to match the Debricked core repository according to the list below. If you’re not using the variable group from step 1, remove the variables section from the triggering template:
    • <variable_group_name>: Name of the variable group created in step 1
    • <repository_reference>: Named reference of your choice
    • <repository_type>: github
    • <username_or_project>: debricked
    • <repository_name>: cli
    • <service_connection_name>: The name of the service connection created in step 2
    • <resource_template_file_name>: examples/templates/Azure/azure-pipelines.yml

Option 2: Using your own core repository in Azure DevOps

By using your own core repository containing the template in Azure DevOps, you do not need to create a service connection and can customise the template to your liking.

  1. Create a new repository in your organisation or use an already existing one as the core.
  2. Paste the Debricked template contents from the Debricked template into an azure pipelines yaml file. If you would like to set up scanning in this repository as well and want to use the variable group from step 1, add the variables section from the triggering template above into the template under the “debricked_scan” job.
  3. In the repositories that you want to trigger the shared pipeline from, paste the triggering template above to an azure pipelines yaml file. If you’re not using a service connection, you should remove the endpoint variable from the triggering template.
  4. Fill in the variables to match the chosen core repository according to the list below. If you’re not using the variable group from step 1, remove the variables section from the triggering template:
    • <variable_group_name>: Name of the variable group created in step 1
    • <repository_reference>: Named reference of your choice
    • <repository_type>: git
    • <username_or_project>: The name of the azure project containing your core repository
    • <repository_name>: The name of the core repository
    • <service_connection_name>: Not needed if the core repository exists in your organisation, remove the endpoint variable
    • <resource_template_file_name>: The path/name to the template file in your core repository

 

Credentials for pull requests

Debricked can generate pull requests for you, but to be able to use it in Azure DevOps, you also need to provide us with credentials such that we can create the pull request on your Azure DevOps instance.

You can generate a Personal access token by going to the User settings -> Personal access tokens. You need to:

  1. Select your organization (or you can create token for all accessible organizations);
  2. Set custom expiration date to the maximum possible value
  3. Grant the token the Code (Read, write, & manage) scope
  4. Then when you try to create a Pull Request inside the Debricked tool, it will automatically ask you for your credentials when needed
  5. Fill out the form:
  • Host: enter the domain, e.g.: "https://dev.azure.com/", "https://azure.yourcompany.com", "https://org.visualstudio.com"
  • Token: enter the personal access token created before and enter
  1. After clicking Confirm, the merge request generation will start


Opening a Debricked generated Pull Request on Azure DevOps - video guide

 


0 replies

Be the first to reply!

Reply