我想从nexus的存储库中获取工件。我不知道如何在Active Choice Parameter中编写groovy脚本。我在Jenkins中使用Nexus3平台插件。但它只允许一个管道中有一个存储库。我想用它作为动态参数。我不知道什么是时髦的剧本。任何帮助都将不胜感激。先谢谢你。我尝试了下面的代码,但它没有显示任何东西。
import groovy.json.JsonSlurper import javax.ws.rs.client.ClientBuilder
// Nexus API endpoint and credentials
def nexusUrl = "https://nexus.xxx.xxx"
def nexusUsername = "admin"
def nexusPassword = "xxxxxx"
// Nexus repository and group ID
def repositoryId = "maven-releases"
def groupId = "xxx.xxx"
// Fetch artifacts from Nexus
def fetchArtifactsFromNexus() {
def artifacts = []
def apiUrl = "${nexusUrl}/service/rest/v1/search/assets?repository=${repositoryId}&group=${groupId}"
// Create a client and set authentication credentials
def client = ClientBuilder.newClient()
client.property('http.connection.timeout', 5000)
client.property('http.receive.timeout', 5000)
client.property('http.send.timeout', 5000)
// Set authentication credentials
client.register(HttpAuthenticationFeature.basic(nexusUsername, nexusPassword))
// Make the request and parse the JSON response
def response = client.target(apiUrl).request().get()
def responseJson = new JsonSlurper().parseText(response.readEntity(String))
// Extract artifact names from the response
responseJson.items.each { item ->
artifacts << item.name
}
return artifacts.join(',')
}
// Execute the script and return the artifacts as a comma-separated string
fetchArtifactsFromNexus()
字符串
1条答案
按热度按时间gblwokeq1#
有新的jenkins plugin。我还是没有用。
My solutuion for nexus rest with groovy URL:
字符串
管道:
型
还有continuationToken用于分割REST结果--您可以使用while循环来获取artifactID的完整列表
复制粘贴流水线
型
jenkinsCREDS只是一些credentials