Code Stream provides a REST plug-in, which allows you to integrate Code Stream with other applications that use a REST API so that you can continuously develop and deliver software applications that must interact with each other. The REST plug-in invokes an API, which sends and receives information between Code Stream and another application.

With the REST plug-in, you can:

  • Integrate external REST API-based systems into a Code Stream pipeline.
  • Integrate a Code Stream pipeline as part of the flow of external systems.

The REST plug-in works with any REST API, and supports GET, POST, PUT, PATCH, and DELETE methods to send or receive information between Code Stream and other applications.

Table 1. Preparing a pipeline to communicate over the REST API
What you do What happens as a result
Add a REST task to your pipeline.

The REST task communicates information between applications, and can provide status information for a successive task in the pipeline stage.

In the REST task, select the REST action and include the URL.

The pipeline task calls the URL when the pipeline runs.

For POST, PUT, and PATCH actions, you must include a payload. In the payload, you can bind your pipeline and task properties when the pipeline runs.

Consider this example.

Example use of the REST plug-in:

You can add a REST task to create a tag on a Git commit for a build, and have the task post a request to get the check-in ID from the repository. The task can send a payload to your repository and create a tag for the build, and the repository can return the response with the tag.

Similar to using the REST plug-in to invoke an API, you can include a Poll task in your pipeline to invoke a REST API and poll it until it completes and the pipeline task meets the exit criteria.

You can also use REST APIs to import and export a pipeline, and use the example scripts to run a pipeline.

This procedure gets a simple URL.

Procedure

  1. To create a pipeline, click Pipelines > New Pipeline > Blank Canvas.
  2. In your pipeline stage, click + Sequential Task.
  3. In the task pane, add the REST task:
    1. Enter a name for the task.
    2. In the Type drop-down menu, select REST.
    3. In the REST Request area, select GET.
      To have the REST task request data from another application, you select the GET method. To send data to another application, you select the POST method.
    4. Enter the URL that identifies the REST API endpoint. For example, https://www.google.com.
      For a REST task to import data from another application, you can include the payload variable. For example, for an import action, you can enter ${Stage0.export.responseBody}. If the response data size exceeds 5 MB, the REST task might fail.
    5. To provide authorization for the task, click Add Headers and enter a header key and value.
    When you add a REST task, and configure the REST request, you select the action, enter the URL, and add any headers for authorization.
  4. To save your pipeline, click Save.
  5. On the pipeline tab, click Enable pipeline.
    Before the pipeline can run, you must enable it.
  6. Click Save, then click Close.
  7. Click Run.
  8. To watch the pipeline run, click Executions.
    After the pipeline starts to run, you can observe the pipeline status as it runs.
  9. To verify that the REST task returns the information you expect, examine the pipeline execution and the task results.
    1. After the pipeline completes, to confirm that the other application returned the data you requested, click the link to the pipeline execution.
    2. Click the REST task in the pipeline.
    3. In the pipeline execution, click the task, observe the task details, and verify that the REST task returned the expected results.
      The task details display the response code, body, header keys, and values.
      The details for the REST task display the status as COMPLETED, the response code, the response body, and header keys and values.
  10. To see the JSON output, click VIEW OUTPUT JSON.
    The JSON output for the REST task displays the response headers and response body, and includes the path finder for searching the content.

Results

Congratulations! You configured a REST task that invoked a REST API and sent information between Code Stream and another application by using the REST plug-in.

What to do next

Continue to use REST tasks in your pipelines to run commands and integrate Code Stream with other applications so that you can develop and deliver your software applications. Consider using poll tasks that poll the API until it completes, and the pipeline task meets the exit criteria.