You can use the vRealize Code Stream Poll Plug-in to listen for the status on a specific API to detect when a particular task completes. You configure the interval for the Poll plug-in so that it continues to poll the API until the task meets the exit criteria that you define.

About this task

With the Poll plug-in, you can include an exit criteria for the poll task to stop the polling, and mark the task as completed or failed. The exit criteria can be a success criteria that is mandatory, and an optional failure criteria. The criteria can refer to the JSON response of the API call, and bind to a property value in the JSON response.

You can add and configure a Poll task anywhere in your pipeline. With a Poll task, you can have any other task in the pipeline wait until the status changes on a REST API.

In the task, you enter the URL of any REST endpoint, such as the server that hosts the appliance. In the URL, you include a variable that reflects the output property from the previous task. To verify that the previous task completes, the output must match the criteria that you include in the Poll plug-in task configuration.

You can enter a complex JSON body to search for a specific value. When the value matches the exit condition in the Poll task configuration, the Poll task indicates success or failure. You can include a single exit condition in the Poll task, which must be an On-Success value condition.

Prerequisites

Procedure

  1. In your modeled pipeline, click Add Task to add a task to a stage.
  2. Add a Poll task.
    1. In the Add Task dialog box, click the Provider drop-down menu.
    2. Click Poll Task.
    3. Enter a name for the task, and click OK.
  3. Configure the Poll task.
    1. In the Poll Task, click the gear icon, and click Configure.
    2. In the Task Configuration for Poll Task, enter the URL of any REST endpoint, and include the variable that reflects the output of the previous task.

      You can have the Poll task listen for the status of a JIRA task, and ensure that the Poll task reflects the JIRA issue number. For example, you might enter: http://<URL>:8080/rest/api/2/issue/${Stage0.Jira_Test_Job.issueNumber}. A similar example appears as follows:

    3. In the Interval text box, enter the number of seconds for the Poll task to poll.

      Enter a desired number. A common poll value is 10 seconds, which is the default value.

    4. In the Timeout text box, enter the number of seconds for the Poll task to wait before the task times out.

      Enter a desired number. An adequate timeout might be 500 seconds. The default is 5 seconds.

    5. To continue to poll if the response indicates an error, such as a 404 when the resource is not available, select Ignore Immediate Failure.
    6. To provide authorization for the task, click Add Headers and enter a header key and value.
    7. In the section named Add exit criteria, enter the JSON key path.

    8. At the end of the JSON key path, include the value for the On-Success or On-Failure for the Poll task to detect the matching status.

      For example, in your pipeline, you might have a task to create a JIRA issue. You also have a Poll task to cause the pipeline to wait until the ticket is resolved. The Poll task polls the JSON output from the API, which includes the key path. After the JIRA issue is resolved, the pipeline run succeeds. The JSON output includes the key path components, such as fields, status and name. The JSON code for fields, status and name resembles:

      {
        "expand": "renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations",
        "id": "19982",
        "self": "http://10.110.205.137:8080/rest/api/2/issue/19982",
        "key": "VSD-8479",
        "fields": {
          "issuetype": {
      ...
          "status": {
            "self": "http://10.110.205.137:8080/rest/api/2/status/10000",
            "description": "",
            "iconUrl": "http://10.110.205.137:8080/",
            "name": "Done",
            "id": "10000",
            "statusCategory": {
      ...

    9. Click Save.
  4. Activate and run the pipeline, and view the task execution details.
    1. Click Pipeline Executions, and click the Poll task in the pipeline stage.
    2. In the Task Result dialog box, click the Result drop-down arrow.
    3. Verify that the details display the response code, response body, and the response header keys and values.

      If the response data size exceeds 5 MB, the REST task might fail.

    4. Click the Input drop-down arrow.
    5. View the input details, which include the name and value pairs, the header key and value pairs, JSON key path, and success criteria.

Results

You configured a Poll task to listen for the matching status to detect when a particular task completes, and viewed the task results.