'How to test an API call with Jenkins

I am new to Jenkins. I am calling an API in my pipeline, and writting the results in a file :

stage('Tests') {
            steps {
                bat '''curl "https://api-adress" > APIresults.json'''
            }
        }

Here is the "post" part of my pipeline code:

post {
    success {}
    failure {}
    always {
     archiveArtifacts artifacts: 'APIresults.json', fingerprint: true, followSymlinks: false
    }
 }

My API call return JSON data if you gave the right parameters to the URL, or nothing if you gave wrong parameters.

I would like to know what kind of logic should I put in success to indicate that if something is written in the APIresults.json file then the test is successful.

And in the failure step, if nothing is written in the APIresults.json file, the test failed.

Also I would like the tests to be archived so that I can access them in Blue Ocean.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source