下载最新文章的步骤
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
你完成了。