I am trying to write a query where we have to check all the jobs in success or not built status before the jobs get failed at Release stage.
Try this as a start:
| rest /services/search/jobs
| table dispatchState *.search
That will give you the state of the searches, and the various fields containing the actual searches.
There are dozens of other fields available, just remove the second half of the search above to see the others.
I am looking for splunk jobs, we have jenkins jobs of different stages and we need to write a query where we should define the search in such a way that it checks all the previous jobs and then come to release stage.
How in the world do you expect anybody to be able to help you if you don't even tell us that you mean
Jenkins jobs and not
Splunk jobs? Even then, only those who have those logs can help you unless you post sample data. If you tell us everything and include sample logs then EVERYBODY can help you.