Jenkins Artifactory Plugin AQL 下载最新神器匹配模式
Jenkins Artifactory Plugin AQL download latest artifact matching pattern
我正在将我现有的 Jenkins 作业工作系列移动到现代 Jenkins 作为代码工作流管道的管道中。
随着这一举措的推出,出现了各种新插件,它们提供了 Pipeline 插件可以使用的步骤。其中之一是 Jenkins Artifactory 插件。
此插件可以接受 Artifactorys "AQL" 语言的 json 对象,或者相反,一个非常简单的模式,用于在一系列回购中搜索与模式匹配的 Artifacts。
我已经尝试使用 "AQL" 和模式来解决我的问题。
我遇到的问题是,我想模仿可在 Jenkins Jobs 中使用的现有 Jenkins Artifact Resolver 插件的行为。
此插件使用我目前提供给 DSL 工作流程的相同模式,并且只下载特定 return 集中的最新或最后修改的工件。我想对我的新方法做同样的事情。
这是使用基于模式的搜索的结果:
jfrog rt search "client-snapshots/com/client/content_services/search-dist/*.zip"
[Info:] Pinging Artifactory...
[Info:] Done pinging Artifactory.
[Info:] Searching Artifactory using AQL query: items.find({"repo": "client-snapshots","$or": [{"$and": [{"path": {"$match":"com/client/content_services/search-dist"},"name":{"$match":"*.zip"}}]},{"$and": [{"path": {"$match":"com/client/content_services/search-dist/*"},"name":{"$match":"*.zip"}}]}]}).include("name","repo","path","actual_md5","actual_sha1","size")
[Info:] Artifactory response: 200 OK
[Info:] Found 58 artifacts.
这是使用来自精心制作的 json 对象的 "AQL" 查询的结果
jfrog rt search --spec art-search.json
[Info:] Pinging Artifactory...
[Info:] Done pinging Artifactory.
[Info:] Searching Artifactory using AQL query: items.find({"repo":"client-snapshots","$and":[{"$or":[{"path":{"$match":"com/client/content_services"},"name":{"$match":"*search*"}}]},{"$or":[{"path":{"$match":"*dist*"},"name":{"$match":".zip"}}]},{"$or":[{"path":{"$match":"*1.0-SNAPSHOT*"},"name":{"$match":"*"}}]}]}).include("name","repo","path","actual_md5","actual_sha1","size")
[Info:] Artifactory response: 200 OK
[Info:] Found 116 artifacts.
以及上述查询的 json:
{
"files": [
{
"aql": {
"items.find": {
"repo": "client-snapshots",
"$and": [
{
"$or": [
{
"path": {
"$match": "com/client/content_services"
},
"name": {
"$match": "*search*"
}
}
]
},
{
"$or": [
{
"path": {
"$match": "*dist*"
},
"name": {
"$match": ".zip"
}
}
]
},
{
"$or": [
{
"path": {
"$match": "*1.0-SNAPSHOT*"
},
"name": {
"$match": "*"
}
}
]
}
]
}
},
"target": "Bazinga/Artifactory/"
}
]
}
第一个 return 只是我指定的 repo 中的 zip,这是我真正想要的。 json 对象 return 是我指定的 repo 中的 poms 和 zips。我可以不用 poms,因为我只对下载 zips 感兴趣。
更重要的是,我想 return 使用上述模式之一的最新 zip。
如有任何建议,我们将不胜感激
所以我找到了使用 AQL 和 PowerShell 的替代解决方案。
$pair = "$($art_user):$($art_pass)"
Write-Verbose "Attempting to convert Artifactory credentials to a base64 string for automation"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$headers = @{
Authorization = $basicAuthValue
}
Write-Host "Attempting to perform a AQL search."
$aql_search = $art_base_url + "/api/search/aql"
Write-Host "Building aql query with the following parameters, groupID: $group_id, artifactID: $artifact_id, version: $version, classifier: $classifier and repos: $art_generic_repokey."
$aql_query = 'items.find({"repo":"' + $art_generic_repokey + '","$or":[{"$and":[{"path":{"$match":"' + $group_id + '/' + $artifact_id + '/' + $version + '"},"name":{"$match":"' + $artifact_id + '*' + $classifier + '*.' + $extension + '"}}]}]}).sort({"$desc":["modified"]}).limit(1)'
Write-Host "Built the following aql query: '$aql_query' ."
$aql_content = Invoke-RestMethod -Uri $aql_search -Headers $headers -Method Post -Body $aql_query -ContentType 'text/plain'
Write-Host "Attempting to submit the aql query to the following artifactory server: $art_base_url."
$aql_results = ($aql_content).results
Write-Host "Attempting to parse query results and build the artifact download uri."
$aql_repo,$aql_path,$aql_name = ($aql_results).repo,($aql_results).path,($aql_results).name
$artifactDownloadUri = $art_base_url + '/' + $aql_repo + '/' + $aql_path + '/' + $aql_name
Write-Host "Found the following uri: $artifactDownloadUri !!"
if ($artifactMimeType -eq 'application/zip' -or $extension -eq 'zip') {
Write-Verbose "Attempting to save the artifact to $download_dir/$art_dist_name.zip"
Invoke-RestMethod -Uri $artifactDownloadUri -Headers $headers -OutFile "$download_dir/$art_dist_name.zip"
}
我正在将我现有的 Jenkins 作业工作系列移动到现代 Jenkins 作为代码工作流管道的管道中。
随着这一举措的推出,出现了各种新插件,它们提供了 Pipeline 插件可以使用的步骤。其中之一是 Jenkins Artifactory 插件。
此插件可以接受 Artifactorys "AQL" 语言的 json 对象,或者相反,一个非常简单的模式,用于在一系列回购中搜索与模式匹配的 Artifacts。
我已经尝试使用 "AQL" 和模式来解决我的问题。
我遇到的问题是,我想模仿可在 Jenkins Jobs 中使用的现有 Jenkins Artifact Resolver 插件的行为。
此插件使用我目前提供给 DSL 工作流程的相同模式,并且只下载特定 return 集中的最新或最后修改的工件。我想对我的新方法做同样的事情。
这是使用基于模式的搜索的结果:
jfrog rt search "client-snapshots/com/client/content_services/search-dist/*.zip"
[Info:] Pinging Artifactory...
[Info:] Done pinging Artifactory.
[Info:] Searching Artifactory using AQL query: items.find({"repo": "client-snapshots","$or": [{"$and": [{"path": {"$match":"com/client/content_services/search-dist"},"name":{"$match":"*.zip"}}]},{"$and": [{"path": {"$match":"com/client/content_services/search-dist/*"},"name":{"$match":"*.zip"}}]}]}).include("name","repo","path","actual_md5","actual_sha1","size")
[Info:] Artifactory response: 200 OK
[Info:] Found 58 artifacts.
这是使用来自精心制作的 json 对象的 "AQL" 查询的结果
jfrog rt search --spec art-search.json
[Info:] Pinging Artifactory...
[Info:] Done pinging Artifactory.
[Info:] Searching Artifactory using AQL query: items.find({"repo":"client-snapshots","$and":[{"$or":[{"path":{"$match":"com/client/content_services"},"name":{"$match":"*search*"}}]},{"$or":[{"path":{"$match":"*dist*"},"name":{"$match":".zip"}}]},{"$or":[{"path":{"$match":"*1.0-SNAPSHOT*"},"name":{"$match":"*"}}]}]}).include("name","repo","path","actual_md5","actual_sha1","size")
[Info:] Artifactory response: 200 OK
[Info:] Found 116 artifacts.
以及上述查询的 json:
{
"files": [
{
"aql": {
"items.find": {
"repo": "client-snapshots",
"$and": [
{
"$or": [
{
"path": {
"$match": "com/client/content_services"
},
"name": {
"$match": "*search*"
}
}
]
},
{
"$or": [
{
"path": {
"$match": "*dist*"
},
"name": {
"$match": ".zip"
}
}
]
},
{
"$or": [
{
"path": {
"$match": "*1.0-SNAPSHOT*"
},
"name": {
"$match": "*"
}
}
]
}
]
}
},
"target": "Bazinga/Artifactory/"
}
]
}
第一个 return 只是我指定的 repo 中的 zip,这是我真正想要的。 json 对象 return 是我指定的 repo 中的 poms 和 zips。我可以不用 poms,因为我只对下载 zips 感兴趣。
更重要的是,我想 return 使用上述模式之一的最新 zip。
如有任何建议,我们将不胜感激
所以我找到了使用 AQL 和 PowerShell 的替代解决方案。
$pair = "$($art_user):$($art_pass)"
Write-Verbose "Attempting to convert Artifactory credentials to a base64 string for automation"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$headers = @{
Authorization = $basicAuthValue
}
Write-Host "Attempting to perform a AQL search."
$aql_search = $art_base_url + "/api/search/aql"
Write-Host "Building aql query with the following parameters, groupID: $group_id, artifactID: $artifact_id, version: $version, classifier: $classifier and repos: $art_generic_repokey."
$aql_query = 'items.find({"repo":"' + $art_generic_repokey + '","$or":[{"$and":[{"path":{"$match":"' + $group_id + '/' + $artifact_id + '/' + $version + '"},"name":{"$match":"' + $artifact_id + '*' + $classifier + '*.' + $extension + '"}}]}]}).sort({"$desc":["modified"]}).limit(1)'
Write-Host "Built the following aql query: '$aql_query' ."
$aql_content = Invoke-RestMethod -Uri $aql_search -Headers $headers -Method Post -Body $aql_query -ContentType 'text/plain'
Write-Host "Attempting to submit the aql query to the following artifactory server: $art_base_url."
$aql_results = ($aql_content).results
Write-Host "Attempting to parse query results and build the artifact download uri."
$aql_repo,$aql_path,$aql_name = ($aql_results).repo,($aql_results).path,($aql_results).name
$artifactDownloadUri = $art_base_url + '/' + $aql_repo + '/' + $aql_path + '/' + $aql_name
Write-Host "Found the following uri: $artifactDownloadUri !!"
if ($artifactMimeType -eq 'application/zip' -or $extension -eq 'zip') {
Write-Verbose "Attempting to save the artifact to $download_dir/$art_dist_name.zip"
Invoke-RestMethod -Uri $artifactDownloadUri -Headers $headers -OutFile "$download_dir/$art_dist_name.zip"
}