Hey All!
Wanted to give you a heads up on some fixes for API trigger failures you might see:
Creating API Trigger
When building out an API Trigger in Harness, you won’t necessarily see something in the Condition that says “API Trigger”. What you should do is set the Condition to “Webhook Event” and leave the “Repository Type” empty.
Issue: No Build/Version Selected
Once you move into the “Actions” section and select either the workflow or pipeline, you’ll see some options for the Build/Version of the artifact to select. These are not designated as a “Required” field, which could lead some to ignore these options entirely. This is where the first error with the API call will come in to play. If you don’t select something in this area, the API call will fail with the following error type {"requestId":null,"status":null,"error":"Invalid request: Workflow requested for execution is not valid/complete.","uiUrl":null,"apiUrl":null,"message":null}
Solution
To solve/prevent the issue, you will need to add a Service Build/Version option in the Triggers “Actions” section.
Issue: API URL Incomplete
When trying to execute an API Trigger, even after fixing the above issue, you might find a problem with an error like {"requestId":null,"status":null,"error":"Invalid argument(s): Application iFCwS31JSY-ci3dlid8O7g doesn't exist","uiUrl":null,"apiUrl":null,"message":null}
.
Solution
The quick solution to this issue is to add ?accountId=<ID>
to the end of the API URL. Example: curl -X POST -H 'content-type: application/json' --url https://app.harness.io/gateway/api/webhooks/<webhook ID>?accountId=<ID> -d '{"application":"<appID"}'
.
Issue: Trigger Executes but Workflow Fails with Incorrect Image
Once you have a trigger that seems to execute successfully and shows a successful response, you may find that your deployment will fail with something related to ${artifact.metadata.image}
in the Context. This is the result of a missing portion in the recommended API trigger command from Harness.
Solution
The solution to this is to provide an artifact section to the payload which dictates the artifact and build/version number. At the end of the parameters
section, you’ll need to add an artifacts
section, which looks something like this:
Before: "parameters":{"Environment":"","Service":"","ServiceInfra_Kubernetes":""}
After: "parameters":{"Environment":"","Service":"","ServiceInfra_Kubernetes":""},"artifacts":[{"service":"","buildNumber":""}]
Once this is added to your API call and filled in with adequate info, you’ll see you trigger execute and the workflow finish out!
Hopefully this will help with any issues that might arise with Triggers. Will update this post as some functionality is improved or if new issues arise.
Don’t forget to Comment/Like/Share!