You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

8 years ago
  1. # Using jq regex so we can support groups
  2. applyRegex_version() {
  3. local regex=$1
  4. local file=$2
  5. jq -n "{
  6. version: $(echo $file | jq -R .)
  7. }" | jq --arg v "$regex" '.version | capture($v)' | jq -r '.version'
  8. }
  9. # retrieve current from artifactory
  10. # e.g url=http://your-host-goes-here:8081/artifactory/api/storage/your-path-goes-here
  11. # regex=ecd-front-(?<version>.*).tar.gz
  12. artifactory_current_version() {
  13. local artifacts_url=$1
  14. local regex=$2
  15. curl $1 | jq --arg v "$regex" '[.children[].uri | capture($v)]' | jq 'sort_by(.version)' | jq '[.[length-1] | {version: .version}]'
  16. }
  17. # Return all versions
  18. artifactory_versions() {
  19. local artifacts_url=$1
  20. local regex=$2
  21. curl $1 | jq --arg v "$regex" '[.children[].uri | capture($v)]' | jq 'sort_by(.version)' | jq '[.[] | {version: .version}]'
  22. }
  23. # return uri and version of all files
  24. artifactory_files() {
  25. local artifacts_url=$1
  26. local regex="(?<uri>$2)"
  27. curl $1 | jq --arg v "$regex" '[.children[].uri | capture($v)]' | jq 'sort_by(.version)' | jq '[.[] | {uri: .uri, version: .version}]'
  28. }
  29. in_file_with_version() {
  30. local artifacts_url=$1
  31. local regex="(?<uri>$2)"
  32. local version=$3
  33. result=$(artifactory_files "$artifacts_url" "$regex")
  34. echo $result | jq --arg v "$version" '[foreach .[] as $item ([]; $item ; if $item.version == $v then $item else empty end)]'
  35. }
  36. # return the list of versions from provided version
  37. check_version() {
  38. local artifacts_url=$1
  39. local regex=$2
  40. local version=$3
  41. result=$(artifactory_versions "$artifacts_url" "$regex") #result=$(curl "$artifacts_url" "$regex")
  42. echo $result | jq --arg v "$version" '[foreach .[] as $item ([]; $item ; if $item.version >= $v then $item else empty end)]'
  43. }