We have the create pipeline api which takes input pipeline yaml and creates corresponding pipeline. The example shared we have is for inline yaml.
Handling yaml as inline as inline input to curl can be challenging due to strict indentation restriction for yaml parsing. This further adds to the complication if we are dealing with a very large and complex pipeline.
Having a way to pass the yaml as a file input to the api helps greatly with such scenario.
Curl do provide a way to pass file as well with yaml but referring file directly as payload can cause issues during yaml parsing. This is because of the fact that each line of a yaml file contains line breaks (\n). Curl removes line breaks when use with the -d option which change the actual yaml format.
We can either explicitly add (\n) to the yaml file which is not optimal for larger yaml.
The better way to handle it is to use --data-binary option instead of -d option when using yaml files as data.
Below is a sample curl for create pipeline api:
curl -i -X POST \ 'https://app.harness.io/gateway/pipeline/api/pipelines/v2?accountIdentifier=xxx&orgIdentifier=someorg&projectIdentifier=someproject' \ -H 'Content-Type: application/yaml' \ -H 'x-api-key: xxxxx' \ --data-binary @test.yaml