So the reason why I've been confused over this bit is because when I run 
your command to get stage history, I get a result which look like this:
{
  "_links" : {
    "previous" : {
      "href" : "https://{COMPANY 
NAME}/go/api/stages/Games-AcesHigh-PHY-Test/Approve/history?before=10780"
    }
  },
  "stages" : [ {
    "name" : "Approve",
    "counter" : "1",
    "approval_type" : "manual",
    "approved_by" : "test1",
    "result" : "Passed",
    "rerun_of_counter" : null,
    "pipeline_name" : "Games-AcesHigh-PHY-Test",
    "pipeline_counter" : 20,
    "jobs" : [ {
      "name" : "Approve",
      "state" : "Completed",
      "result" : "Passed",
      "scheduled_date" : 1611717690867
    } ]
  }, {
    "name" : "Approve",
    "counter" : "1",
    "approval_type" : "manual",
    "approved_by" : "test1",
    "result" : "Passed",
    "rerun_of_counter" : null,
    "pipeline_name" : "Games-AcesHigh-PHY-Test",
    "pipeline_counter" : 18,
    "jobs" : [ {
      "name" : "Approve",
      "state" : "Completed",
      "result" : "Passed",
      "scheduled_date" : 1605826768229
    } ]
  }, {
    "name" : "Approve",
    "counter" : "1",
    "approval_type" : "manual",
    "approved_by" : "test2",
    "result" : "Passed",
    "rerun_of_counter" : null,
    "pipeline_name" : "Games-AcesHigh-PHY-Test",
    "pipeline_counter" : 5,
    "jobs" : [ {
      "name" : "Approve",
      "state" : "Completed",
      "result" : "Passed",
      "scheduled_date" : 1601954345153
    } ]
  } ]

The above JSON are not the most recent results.

However if I were to use this bit of code (with page size set to 100 as it 
seems to be the only way to get the more recent results):

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

I then get (this is just a brief snippet):

{
  "_links" : {
    "previous" : {
      "href" : "https://{COMPANY 
NAME}/go/api/stages/Games-AcesHigh-PHY-Test/Approve/history?before=11468"
    }
  },
  "stages" : [ {
    "name" : "Approve",
    "counter" : "1",
    "approval_type" : "manual",
    "approved_by" : "gabe",
    "result" : "Passed",
    "rerun_of_counter" : null,
    "pipeline_name" : "Games-AcesHigh-PHY-Test",
    "pipeline_counter" : 7,
    "jobs" : [ {
      "name" : "Approve",
      "state" : "Completed",
      "result" : "Passed",
      "scheduled_date" : 1614046479825
    } ]
  }, {
    "name" : "Approve",
    "counter" : "13",
    "approval_type" : "manual",
    "approved_by" : "gabe",
    "result" : "Failed",
    "rerun_of_counter" : null,
    "pipeline_name" : "Games-AcesHigh-PHY-Test",
    "pipeline_counter" : 1,
    "jobs" : [ {
      "name" : "Approve",
      "state" : "Completed",
      "result" : "Failed",
      "scheduled_date" : 1614037130394
    } ]

Neither results matches the stage history shown in GOCD (after clicking on 
job details of the stage I am working on, at the right side, the numbers do 
not match). The pipeline counter is 40+ and the run numbers are either 2, 3 
or 4, which doesn't match the counter in the stage history which shows 1 at 
the most recent instance, the next being 13, 12 and so on. I've attatched 
an image of the stage history. The part that I've circled, is where I 
believe the bottom JSON in the example above matches (since the counter is 
13 in both JSON and the image).

Am I doing something wrong to get a different stage history from what's 
shown in GOCD?

Again, thank you for your patience in assisting me :)

Cheers,
Gabes.
On Tuesday, February 23, 2021 at 6:06:54 PM UTC+13 Marques Lee wrote:

> Yes, so if you're on say, 20.7.0, just add that to your url: 
> https://api.gocd.org/20.7.0/
>
> It looks pretty similar.
>
> -Marques
>
> On Mon, Feb 22, 2021 at 6:06 PM Gabriel Callaghan <
> [email protected]> wrote:
>
>> I just saw that our GOCD is 20.1.0 so it wouldn't be able to use v3 of 
>> this api, as it requires v20.9.0. So that answers my question for why v3 
>> doesn't work. However in GOCD api list, it only shows v3+, so i cant check 
>> for what it looks like when using v2. Would anyone know how to get the most 
>> recent history rather than filtered? I don't want to be only shown passed 
>> results, I want to see failed ones as well.
>>
>> On Tuesday, February 23, 2021 at 1:03:00 PM UTC+13 Gabriel Callaghan 
>> wrote:
>>
>>> 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/5cb8a558-ed85-4021-b4ed-564d1d11f460n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/go-cd/5cb8a558-ed85-4021-b4ed-564d1d11f460n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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/3b8debc9-2efb-4b57-8d74-a78a6378212an%40googlegroups.com.

Reply via email to