下載最新文章的步驟

1.獲取最後修改(最新)工件的 JSON 響應

latestArtifactUriResponse=curl -u username:password --silent https://hostname.com/artifactory/api/storage/<repo_name>/<folder_name>/?lastModified | grep uri | awk '{ print $3 }' | sed s/\"//g | sed s/,//g

它將以以下格式返回響應:

{
  "uri" : "https://hostname.com/artifactory/api/storage/<repo_name>/<folder_name>/latest_artifact.tar.gz",
  "lastModified" : "2016-12-22T04:26:25.534-0500"
}

2.從 latestArtifactUriResponse 獲取最新工件的直接 URL

latestArtifactUriReponse 將以以下格式返回響應:

{
  "repo" : "repo_name",
  "path" : "/folder_name/latest_artifact.tar.gz",
  "created" : "2016-12-22T04:26:29.482-05:00",
  "createdBy" : "username",
  "lastModified" : "2016-12-22T04:26:25.534-05:00",
  "modifiedBy" : "username",
  "lastUpdated" : "2016-12-22T04:26:25.534-05:00",
  "downloadUri" : "https://hostname.com/artifactory/repo_name/folder_name/latest_artifact.tar.gz",
  "mimeType" : "application/octet-stream",
  "size" : "94310686",
  "checksums" : {
    "sha1" : "ocb778e566890b0f3d115b828ce8dd4e840",
    "md5" : "d050fb8108745973cf0d64e15667b340"
  },
  "originalChecksums" : {
  },
  "uri" : "https://hostanme.com/artifactory/api/storage/repo_name/folder_name/latest_artifact.tar.gz"
}    

這裡我們要獲取 downloadUri 的值,這是最新 artifcat 的直接 URL 並將其儲存在 downloadUrl 變數中:

downloadUrl=`curl -u username:password --silent $latestArtifactUrl | grep downloadUri | awk '{ print $3 }' | sed s/\"//g | sed s/,//g`    

3.下載最新的工件

curl -u username:password -O $downloadUrl

你完成了。