IBM Cloud Docs
Creating toolchains with Git

Creating toolchains with Git

You can use a template that contains either a Git Repos and Issue Tracking or GitHub tool integration as a starting point to create a toolchain that you can add Git repositories (repos) to. Alternatively, you can start with either an empty toolchain or an existing toolchain and then add a Git Repos and Issue Tracking or GitHub tool integration to it.

To see which toolchain templates contain the Git Repos and Issue Tracking or GitHub tool integrations, see Toolchain availability, templates, and tutorials.

Creating a toolchain from a template with Git Repos and Issue Tracking or GitHub by using the console

You can use a template as a starting point to create a toolchain that includes either a Git Repos and Issue Tracking or GitHub tool integration. Learn more about how to use the templates from the IBM Cloud Garage Method.

  1. Log in to IBM Cloud.

  2. From the IBM Cloud console, click the menu icon hamburger icon and select DevOps.

  3. On the DevOps dashboard, on the Toolchains page, click Create a Toolchain.

  4. On the Create a Toolchain page, click a toolchain template.

  5. Review the diagram of the toolchain that you are about to create. The diagram shows each tool integration in its lifecycle phase in the toolchain.

  6. Review the default information for the toolchain settings:

    • The toolchain's name identifies it in IBM Cloud. If you want to use a different name, change the toolchain's name.
    • The region to create the toolchain in. If you want to use a different region, select it from the list of available regions.
    • The resource group to create the toolchain in. If you want to use a different resource group, select it from the list of available resource groups.
    • The provider for your source repository, such as GitHub or GitLab. If you want to use a different source provider, select it from the list of available repos.
  7. In the Tool Integrations section, select each tool integration that you want to configure for your toolchain. For more information about configuring the tool integrations, see Configuring tool integrations.

  8. Click Create. Several steps run automatically to set up your toolchain. The tool integrations that are set up are different depending on which toolchain template you selected. For example, when you create a Microservices toolchain on IBM Cloud Public, these steps are run:

    • The toolchain is created.
    • If you configured Delivery Pipeline, the pipelines are created and triggered.
    • If you configured Sauce Labs, the toolchain is set up to add Sauce Labs test jobs to the pipelines.
    • If you configured Event Notifications, the toolchain is set up to send event notifications to the Event Notifications service that you specified.
    • If you configured PagerDuty, the toolchain is set up to send alert notifications to the PagerDuty service that you specified.
    • If you configured Slack, the toolchain is set up to send notifications about deployment status to the Slack channel that you specified.
    • If you configured a source code tool integration such as GitHub, the sample GitHub repo is cloned into your GitHub account.

    You can now distribute event notifications by using the Event Notifications tool integration. IBM Cloud Event Notifications is the preferred method for distributing notifications to PagerDuty and other communication channels such as Slack, email, SMS, push notifications, webhook, Microsoft® Teams, ServiceNow, and IBM Cloud Functions. For more information about using Event Notifications, see Enabling event notifications for toolchains.

Creating a toolchain from a template with Git Repos and Issue Tracking or GitHub with the API

You can create a toolchain from a template only by using the console. To view the steps for using the console, switch to the UI instructions.

For more information about how to create a toolchain with the API instead of by using a template, see Adding the Git tool integration to an existing toolchain with the API.

Creating a toolchain from a template with Git Repos and Issue Tracking or GitHub with Terraform

You can create a toolchain from a template only by using the console. To view the steps for using the console, switch to the UI instructions.

For more information about how to create a toolchain with Terraform instead of by using a template, see Adding the Git tool integration to an existing toolchain with Terraform.

Adding the Git tool integration to an existing toolchain by using the console

You can add a Git tool integration to any existing toolchain by using the console.

  1. Log in to IBM Cloud.
  2. From the IBM Cloud console, click the menu icon hamburger icon and select Resource list.
  3. From the Resource list, expand the Developer tools section.
  4. Either click a toolchain to which you want to add a Git tool integration, or create a toolchain. For information about creating toolchains, see Creating toolchains.
  5. On the Toolchain's Overview page, click Add Tool, and then select GitHub or Git Repos and Issue Tracking to add either of these tool integrations to your toolchain.
  6. Depending on which Git tool integration you select, you can configure the the GitHub tool integration or you can configure the Git Repos and Issue Tracking tool integration.

Adding the Git tool integration to an existing toolchain with the API

You can add a Git tool integration to any existing toolchain with the API.

  1. Obtain an IAM bearer token. Alternatively, if you are using an SDK, obtain an IAM API key and set the client options by using environment variables.

    export CD_TOOLCHAIN_AUTH_TYPE=iam && \
    export CD_TOOLCHAIN_APIKEY={iam_api_key} && \
    export CD_TOOLCHAIN_URL=https://api.{region}.devops.cloud.ibm.com/toolchain/v2
    
  2. Determine the region and ID of the toolchain that you want to add the Git tool integration to.

  3. Add the Git tool integration to the toolchain. The following example shows how to add a Git tool integration that links to an existing repo on github.com. You can also add a Git tool integration with instructions to create, fork, or clone a new repo. And you can add tool integrations for other GitHub, GitLab, or Bitbucket servers.

    curl -X POST \
      https://api.{region}.devops.cloud.ibm.com/toolchain/v2/toolchains/{toolchain_id}/tools \
      -H 'Authorization: Bearer {token}' \
      -H 'Accept: application/json` \
      -H 'Content-Type: application/json' \
        -d '{
        "tool_type_id": "githubconsolidated",
        "name": "{tool_integration_name}",
        "parameters": {
          "type": "link",
          "git_id": "github",
          "repo_url": "https://github.com/{git_org}/{git-repo}.git",
          "has_issues": true
        }
      }'
    
    const CdToolchainV2 = require('@ibm-cloud/continuous-delivery/cd-toolchain/v2');
    const toolchainService = CdToolchainV2.newInstance();
    ...
    (async() => {
       const gitToolModel = {
          toolchainId: {toolchain_id},
          toolTypeId: 'githubconsolidated',
          name: {tool_integration_name},
          parameters: {
             type: 'link',
             git_id: 'github',
             repo_url: 'https://github.com/{git_org}/{git-repo}.git',
             has_issues: true,
    
          }
       };
       const gitTool = await toolchainService.createTool(gitToolModel);
    })();
    
    import (
        "github.com/IBM/continuous-delivery-go-sdk/cdtoolchainv2"
    )
    ...
    toolchainClientOptions := &cdtoolchainv2.CdToolchainV2Options{}
    toolchainClient, err := cdtoolchainv2.NewCdToolchainV2UsingExternalConfig(toolchainClientOptions)
    createGitToolOptions := toolchainClient.NewCreateToolOptions({toolchain_id}, "githubconsolidated")
    gitParameters := map[string]interface{}{
     "type": "link",
     "git_id": "github",
     "repo_url": "https://github.com/{git_org}/{git-repo}.git",
     "has_issues": true,
    }
    createGitToolOptions.SetName({tool_integration_name})
    createGitToolOptions.SetParameters(gitParameters)
    gitTool, response, err := toolchainClient.CreateTool(createGitToolOptions)
    
    from ibm_continuous_delivery.cd_toolchain_v2 import CdToolchainV2
    ...
    toolchain_service = CdToolchainV2.new_instance()
    git_parameters = {
       "type": "link",
       "git_id": "github",
       "repo_url": "https://github.com/{git_org}/{git-repo}.git",
       "has_issues": True
    }
    git_tool = toolchain_service.create_tool(
       name = {tool_integration_ame},
       toolchain_id = {toolchain_id},
       tool_type_id = "githubconsolidated",
       parameters = git_parameters
    )
    
    import com.ibm.cloud.continuous_delivery.cd_toolchain.v2.CdToolchain;
    import com.ibm.cloud.continuous_delivery.cd_toolchain.v2.model.*;
    ...
    CdToolchain toolchainService = CdToolchain.newInstance();
    HashMap<String, Object> gitParameters = new HashMap<>();
    gitParameters.put("type", "link");
    gitParameters.put("git_id", "github");
    gitParameters.put("repo_url", "https://github.com/{git_org}/{git-repo}.git");
    gitParameters.put("has_issues", true);
    CreateToolOptions createGitToolOptions = new CreateToolOptions.Builder()
       .name({tool_integration_name})
       .parameters(gitParameters)
       .toolchainId({toolchain_id})
       .toolTypeId("githubconsolidated")
       .build();
    Response<ToolchainToolPost> response = toolchainService.createTool(createGitToolOptions).execute();
    ToolchainToolPost gitTool = response.getResult();
    

The following table lists and describes each of the variables that are used in the previous steps.

Table 1. Variables for adding the Git tool integration with the API
Variable Description
{git_org} The organization on github.com that contains the repo.
{git_repo} The repo on github.com to integrate into the toolchain.
{iam_api_key} Your IAM API key.
{region} The region in which the toolchain resides. For example, us-south.
{tool_integration_name} A name for your tool integration.
{toolchain_id} The ID of the toolchain to which to add the tool integration.
{token} A valid IAM bearer token.

For more information about each of the Git tool integrations, including additional parameters that you can configure, see the following topics:

Adding the Git tool integration to an existing toolchain with Terraform

You can add a Git tool integration to any existing toolchain with Terraform.

  1. To install the Terraform CLI and configure the IBM Cloud provider plug-in for Terraform, follow the tutorial for Getting started with Terraform on IBM Cloud.

  2. Locate the Terraform file (for example, main.tf) that contains the resource block for the toolchain to which you want to add the Git tool integration. In this file, add the configuration to create the tool integration.

    The following example creates the toolchain if it does not exist and then adds a Git tool integration that links to an existing repo on github.com by using the ibm_cd_toolchain_tool_githubconsolidated resource. You can also add a Git tool integration with instructions to create, fork, or clone a new repo. And you can add tool integrations for other GitHub, GitLab, or Bitbucket servers.

    data "ibm_resource_group" "group" {
      name = "default"
    }
    
    resource "ibm_cd_toolchain" "cd_toolchain" {
      name              = "my toolchain"
      resource_group_id = data.ibm_resource_group.group.id
    }
    
    resource "ibm_cd_toolchain_tool_githubconsolidated" "my-github-tool-integration" {
      toolchain_id = ibm_cd_toolchain.cd_toolchain.id
      initialization {
        git_id = "github"
        repo_url = "https://github.com/my-org/my-repo.git"
        type = "link"
        auth_type = "pat"
        api_token = "<TOKEN>"
      }
      parameters {
        has_issues = true
      }
    }
    

    Where <TOKEN> represents a Personal Access Token (PAT) that belongs to the GitHub account that grants access to the target repo.

  3. Initialize the Terraform CLI.

    terraform init
    
  4. Create a Terraform execution plan. This plan summarizes all of the actions that must run to add the DevOps Insights tool integration to the toolchain.

    terraform plan
    
  5. Apply the Terraform execution plan. Terraform takes all of the required actions to add the DevOps Insights tool integration to the toolchain.

    terraform apply
    

For more information about each of the Git tool integration resources, including additional parameters that you can configure, see the argument reference details in the Terraform Registry documentation:

For more information about using Terraform with Continuous Delivery, see Setting up Terraform for Continuous Delivery.