Hi,

I am running into some different results than what I wanted. My goal is to 
use jq to filter results of the "get stage history" 
(https://api.gocd.org/current/#get-stage-history) so that I can get the 
most recent run and to check it for if it has been passed or not.

At the moment, I am using that API with v2+ on the third line as it 
provides results. If I change it to v3+, it gets "<html><body><h2>404 Not 
found</h2></body></html>". This is why I have been using it as v2+. 
However, when using v2+ I am getting back weird results. It does not seem 
to be in order from most recent results to the oldest, it is being filtered 
somehow? It means that as a result, my script is trying to run a pipeline 
that is an older version, when it should be checking and running the most 
recent version of a pipeline. 

Why is it doing that, and what can I do to make sure that the stage history 
json provides results from the most recent to the latest?

If it helps, my current script is this:

#! /bin/bash

fetchPipelineHistory=$( curl "{COMPANY 
NAME}/go/api/stages/Games-AcesHigh-PHY-Test/Approve/history" \
      -H "Authorization: Bearer {MY TOKEN)" \
      -H 'Accept: application/vnd.go.cd.v2+json')

getResultOfCurrentStage=$( echo $fetchPipelineHistory | jq -r 
'.stages[].result')

counter=$( echo $fetchPipelineHistory | jq -r '.stages[0].counter')

if [ "$getResultOfCurrentStage" != "Passed" ]
then

echo "{COMPANY 
NAME}/api/stages/Games-AcesHigh-PHY-Test/$counter/Approve/run"

curl "{COMPANY 
NAME}/go/api/stages/Games-AcesHigh-PHY-Test/$counter/Approve/run" \
      -H "Authorization: Bearer {MY TOKEN}" \
      -H 'X-GoCD-Confirm: true' \
      -H 'Accept: application/vnd.go.cd.v2+json' \
      -X POST

fi

Thank you for reading,
Gabes.


-- 
You received this message because you are subscribed to the Google Groups 
"go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/go-cd/bcb78dac-5cdb-4216-ad87-a9e56291ef4an%40googlegroups.com.

Reply via email to