1

After executing this query in Artifactory

/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip

I have this output:

[Info] Searching artifacts...
[Info] Found 3 artifacts.
[
  {
    "path": "foo/01_Develop/01_CI/HPCC-Package-47.zip"
  },
  {
    "path": "foo/01_Develop/01_CI/HPCC-Package-48.zip"
  },
  {
    "path": "foo/01_Develop/01_CI/HPCC-Package-72.zip"
  }
]

I want to get the last path in json array with this command as suggested here:

/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq .[-1].path

But fails with

parse error: Invalid numeric literal at line 1, column 6

I cannot change json as it is the output from artifactory jfrog tool

  • How can I fix JQ query?
  • Is there any other way to get the last path?

NOTE: I have jq version 1.5

UPDATE:

Using quotes I have the exact same error:

/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq '.[-1].path'
/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | jq ".[-1].path"
Community
  • 1
  • 1
Oscar Foley
  • 6,817
  • 8
  • 57
  • 90

3 Answers3

4

As mentioned in previous answers, this error occurred because the output of JFrog CLI is not pure JSON.
You may want to set the JFROG_CLI_LOG_LEVEL environment variable to ERROR, so that additional messages will not be prompted by the command.
For more details you can read JFrog CLI wiki.

Dima Nevelev
  • 388
  • 1
  • 10
3

Your Artifactory output isn't pure json... you need to remove those non-json parts. Assuming we will only need to skip the first two lines, we could just use tail to skip em.

/usr/bin/jfrog rt s foo/01_Develop/01_CI/HPCC-Package-*.zip | tail -n +3 | jq '.[-1].path'
Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
1

For the record, here's a jq-only solution that assumes there are exactly two lines of non-JSON prolog:

... | jq -n -R -r '[inputs][2:] | join("") | fromjson[-1]' 
{
  "path": "foo/01_Develop/01_CI/HPCC-Package-72.zip"
}
peak
  • 105,803
  • 17
  • 152
  • 177