How do I use a REST API to integrate
Automation Pipelines with other applications
Automation Pipelines
with other applicationsAutomation Pipelines
provides a REST plug-in, which allows you to integrate Automation Pipelines
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 Automation Pipelines
and
another application. With the REST plug-in, you can:
- Integrate external REST API-based systems into aAutomation Pipelinespipeline.
- Integrate aAutomation Pipelinespipeline 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
Automation Pipelines
and other applications. 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 get information that
is needed for a subsequent pipeline task. |
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. See What types of tasks are available in Automation Pipelines.
You can also use REST APIs to import and
export a pipeline, and use the example scripts to run a pipeline.
In this procedure, the REST task gets a build tag from
one service and a subsequent CI task uses the build tag to get a CICD build number.
- To create a pipeline, click.
- In your pipeline stage, click+ Sequential Task.
- In the task pane, add the REST task:
- Enter a name for the task.
- In the Type drop-down menu, selectREST.
- In the REST Request area, selectGET.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.
- Enter the URL that identifies the REST API endpoint used to obtain the build tag. For example:https://devops.mycompany.com:8001/job/service-build/api/jsonAutomation Pipelinesdoes not support%2Fas URL encoding for/as in:
When specifying the REST API endpoint, use a basic URL format such as:https://gitlab.com/api/v4/projects/1234567/repository/files/FOLDERNAME%2Ftest.yamlhttps://gitlab.com/api/v4/projects/1234567/repository/files/FOLDERNAME/test.yaml${Stage0.export.responseBody}. If the response data size exceeds 5 MB, the REST task might fail. - To provide authorization for the task, clickAdd Headersand enter header keys and values, such as:KeyValueAcceptapplication/jsonContent-Typeapplication/json
- Add subsequent task that uses information from the REST task response.
- To save your pipeline, clickSave.
- On the pipeline tab, clickEnable pipeline.
- ClickSave, then clickClose.
- ClickRun.
- To watch the pipeline run, clickExecutions.
- To verify that the REST task returns the information you expect, examine the pipeline execution and the task results.
- After the pipeline completes, to confirm that the other application returned the data you requested, click the link to the pipeline execution.
- Click the REST task in the pipeline.
- 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.
- To see the JSON output, clickVIEW OUTPUT JSON.
Congratulations! You configured a REST task
that invoked a REST API and sent information between
Automation Pipelines
and another application by using the REST plug-in. Continue to use REST tasks in your pipelines to run
commands and integrate
Automation Pipelines
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.