keptn-sandbox / keptn-azure-devops-extension

Azure DevOps Extension for integrating Keptn with your Azure DevOps Pipelines
Apache License 2.0
6 stars 4 forks source link

Research which tasks can be implemented using `HttpRequest` or `HttpRequestChain` execution #55

Open christian-kreuzberger-dtx opened 2 years ago

christian-kreuzberger-dtx commented 2 years ago

I found this in the Azure DevOps examples: https://github.com/microsoft/azure-pipelines-extensions/blob/78bf251236c84c4da622c125764b7e7434e98a2a/Extensions/ServiceNow/Src/Tasks/UpdateChangeRequest/UpdateChangeRequestV2/task.json#L118-L162

Basically it means that instead of

  "execution": {
    "Node10": {
      "target": "index.js",
      "argumentFormat": ""
    }
  }

it is possible to use a http request chain, e.g.:

"Execute": [{
          "RequestInputs": {
            "EndpointId": "$(ServiceNowConnection)",
            "EndpointUrl": "$(endpoint.url)/api/now/table/change_request?sysparm_query=number=$(ChangeRequestNumber)&sysparm_fields=number,correlation_id",
            "Method": "GET",
            "Headers": "{\"Content-Type\":\"application/json\", \"Accept\":\"application/json\"}",
            "WaitForCompletion": "false",
            "Expression": "eq(count(root['result']), 1)"
          },
          "ExecutionOptions": {
            "OutputVariables": "{\"CHANGE_REQUEST_NUMBER\" :  \"jsonpath('$.result[0].number')[0]\", \"CHANGE_CORRELATION_ID\" :  \"jsonpath('$.result[0].correlation_id')[0]\"}",
            "SkipSectionExpression": "eq(isNullOrEmpty(taskInputs['ChangeRequestNumber']), true)"
          }
        },

 {
          "RequestInputs": {
            "EndpointId": "$(ServiceNowConnection)",
            "EndpointUrl": "$(endpoint.url)/api/now/import/x_mioms_azpipeline_change_request_import",
            "Method": "POST",
            "Body": "{\"u_number\": \"$(CHANGE_REQUEST_NUMBER)\",\"u_correlation_id\": \"$(CHANGE_CORRELATION_ID)\",\"u_work_notes\": \"$(WorkNotes)\"{{#equals UpdateStatus 'true'}},\"u_state\": \"$(NewStatus)\"{{#equals '$(NewStatus)' '3' 1}}, \"u_close_code\": \"$(CloseCode)\", \"u_close_notes\": \"$(CloseNotes)\"{{/equals}}{{/equals}}{{#if otherParameters}}{{toCommaSeparatedKeyValueList otherParameters true}}{{/if}} }",
            "Headers": "{\"Content-Type\":\"application/json\", \"Accept\":\"application/json\"}",
            "WaitForCompletion": "false",
            "Expression": "eq(jsonpath('$.result[0].status')[0], 'updated')"
          }
        }

Another way I found is

  "execution": {
    "HttpRequest": {
      "Execute": {
        "EndpointId": "$(XYZServerConnection)",
        "EndpointUrl": "$(endpoint.url)$(urlSuffix)",
        "Method": "GET",
        "Headers": "{\"Content-Type\":\"application/json\", \"Accept\":\"application/json\"}",
        "WaitForCompletion": "false",
        "Expression": "$(successCriteria)"
      }
    }

IMO it could be viable to do this for certain tasks (e.g., creating a service, creating a project, sending a CloudEvent, etc...), which would save us some lines of code.

Definition of Done