如何使用 groovy 从 Artifactory 仓库获取目录列表
How to get list of directories from Artifactory repo using groovy
我的 Jenkins Active 选择参数之一中有以下 groovy 脚本:
import groovy.json.JsonSlurper
import jenkins.model.Jenkins
versions = getArtifactsVersions()
def getArtifactsVersions(){
def responseJson = "curl -k -X GET https://{Artifatory_URL}/storage/my-repo/".execute().text
def projectList = (new groovy.json.JsonSlurper().parseText(responseJson)).children
return projectList
}
它应该是 return 存在于该路径中的文件夹列表(没有子目录),但是,我从中得到的结果是:
{uri=/TEST_FOR_YONI, folder=true}
{uri=/TEST_FOR_PKMLODEL_V2, folder=true}
如何更改为return:
TEST_FOR_YONI
TEST_FOR_PKMLODEL_V2
为了调试,我运行以下:
import groovy.json.JsonSlurper
import jenkins.model.Jenkins
def responseJson = "curl -k -X GET https://{Artifatory_URL}/storage/my-repo/".execute().text
print responseJson
并重新运行以下内容:
{
"repo" : "my-repo",
"path" : "/",
"created" : "2020-11-29T18:00:42.635+02:00",
"lastModified" : "2020-11-29T18:00:42.635+02:00",
"lastUpdated" : "2020-11-29T18:00:42.635+02:00",
"children" : [ {
"uri" : "/TEST_FOR_YONI",
"folder" : true
}, {
"uri" : "/TEST_FOR_PKLMODEL_V2",
"folder" : true
}
],
"uri" : "https://{Artifatory_URL}/storage/my-repo/"
}
def responseJson='''
{
"repo" : "my-repo",
"path" : "/",
"created" : "2020-11-29T18:00:42.635+02:00",
"lastModified" : "2020-11-29T18:00:42.635+02:00",
"lastUpdated" : "2020-11-29T18:00:42.635+02:00",
"children" : [ {
"uri" : "/TEST_FOR_YONI",
"folder" : true
}, {
"uri" : "/TEST_FOR_PKLMODEL_V2",
"folder" : true
}
],
"uri" : "https://{Artifatory_URL}/storage/my-repo/"
}
'''
def projectList = new groovy.json.JsonSlurper().parseText(responseJson).children.collect{ it.uri.substring(1) }
我的 Jenkins Active 选择参数之一中有以下 groovy 脚本:
import groovy.json.JsonSlurper
import jenkins.model.Jenkins
versions = getArtifactsVersions()
def getArtifactsVersions(){
def responseJson = "curl -k -X GET https://{Artifatory_URL}/storage/my-repo/".execute().text
def projectList = (new groovy.json.JsonSlurper().parseText(responseJson)).children
return projectList
}
它应该是 return 存在于该路径中的文件夹列表(没有子目录),但是,我从中得到的结果是:
{uri=/TEST_FOR_YONI, folder=true}
{uri=/TEST_FOR_PKMLODEL_V2, folder=true}
如何更改为return:
TEST_FOR_YONI
TEST_FOR_PKMLODEL_V2
为了调试,我运行以下:
import groovy.json.JsonSlurper
import jenkins.model.Jenkins
def responseJson = "curl -k -X GET https://{Artifatory_URL}/storage/my-repo/".execute().text
print responseJson
并重新运行以下内容:
{
"repo" : "my-repo",
"path" : "/",
"created" : "2020-11-29T18:00:42.635+02:00",
"lastModified" : "2020-11-29T18:00:42.635+02:00",
"lastUpdated" : "2020-11-29T18:00:42.635+02:00",
"children" : [ {
"uri" : "/TEST_FOR_YONI",
"folder" : true
}, {
"uri" : "/TEST_FOR_PKLMODEL_V2",
"folder" : true
}
],
"uri" : "https://{Artifatory_URL}/storage/my-repo/"
}
def responseJson='''
{
"repo" : "my-repo",
"path" : "/",
"created" : "2020-11-29T18:00:42.635+02:00",
"lastModified" : "2020-11-29T18:00:42.635+02:00",
"lastUpdated" : "2020-11-29T18:00:42.635+02:00",
"children" : [ {
"uri" : "/TEST_FOR_YONI",
"folder" : true
}, {
"uri" : "/TEST_FOR_PKLMODEL_V2",
"folder" : true
}
],
"uri" : "https://{Artifatory_URL}/storage/my-repo/"
}
'''
def projectList = new groovy.json.JsonSlurper().parseText(responseJson).children.collect{ it.uri.substring(1) }