Automatiser la création des ressources en fonction du tag
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
This commit is contained in:
@ -1,5 +1,38 @@
|
||||
import groovy.json.JsonOutput
|
||||
|
||||
def getResourceHREF(
|
||||
String credentials,
|
||||
String resourceEndpoint,
|
||||
String resourceName
|
||||
) {
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
||||
if (resource) {
|
||||
return resource.pulp_href
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
def waitForTaskCompletion(
|
||||
String credentials,
|
||||
String taskHREF,
|
||||
String pulpHost = '192.168.30.3'
|
||||
) {
|
||||
def status = ''
|
||||
def created_resources = []
|
||||
while (status != 'completed') {
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
status = jsonResponse.state
|
||||
if (status == 'completed') {
|
||||
created_resources = jsonResponse.created_resources
|
||||
}
|
||||
sleep(10)
|
||||
}
|
||||
return created_resources
|
||||
}
|
||||
|
||||
def exportPackages(
|
||||
String credentials,
|
||||
List packages = [],
|
||||
@ -31,12 +64,9 @@ def getRepositoryHREF(
|
||||
String repository = 'Cadoles4MSE unstable',
|
||||
String pulpHost = '192.168.30.3'
|
||||
) {
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/repositories/deb/apt/", httpMode: 'GET', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
def repositories = jsonResponse.results
|
||||
def repositoryHREF = repositories.find { it -> it['name'] == repository }
|
||||
def repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
|
||||
if (repositoryHREF) {
|
||||
return repositoryHREF.pulp_href
|
||||
return repositoryHREF
|
||||
} else {
|
||||
return createRepository(credentials, repository)
|
||||
}
|
||||
@ -58,9 +88,17 @@ def addToRepository(
|
||||
def publishRepository(
|
||||
String credentials,
|
||||
String repositoryHREF,
|
||||
String signing_service = null
|
||||
String pulpHost = '192.168.30.3'
|
||||
) {
|
||||
def postBody = JsonOutput.toJson(["repository": repositoryHREF, "simple": true])
|
||||
def postContent = ["repository": repositoryHREF, "simple": true]
|
||||
if (signing_service) {
|
||||
def signingServiceHREF = getResourceHREF(credentials, 'signing-services/', signing_service)
|
||||
if (signingServiceHREF) {
|
||||
postContent.put("signing-service", "https://${pulpHost}${signingServiceHREF})
|
||||
}
|
||||
}
|
||||
def postBody = JsonOutput.toJson(postContent)
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/publications/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||
@ -71,23 +109,27 @@ def distributePublication(
|
||||
String publicationHREF,
|
||||
String distributionName,
|
||||
String basePath,
|
||||
String pulpHost = '192.168.30.3',
|
||||
String contentGuard = null
|
||||
String pulpHost = '192.168.30.3',
|
||||
) {
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/distributions/deb/apt/", httpMode: 'GET', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
def httpMode = ''
|
||||
def url = ''
|
||||
def distribution = jsonResponse.results.find { it -> it.name == distributionName}
|
||||
if (distribution) {
|
||||
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
||||
if (distributionHREF) {
|
||||
httpMode = 'PUT'
|
||||
url = distribution.pulp_href
|
||||
|
||||
url = distributionHREF
|
||||
} else {
|
||||
httpMode = 'POST'
|
||||
url = '/pulp/api/v3/distributions/deb/apt/'
|
||||
}
|
||||
def postBody = JsonOutput.toJson(["publication": publicationHREF, "name": distributionName, "base_path": basePath, "content_guard": contentGuard])
|
||||
def bodyContent = ["publication": publicationHREF, "name": distributionName, "base_path": basePath]
|
||||
if (contentGuard) {
|
||||
def contentGuardHREF = getResourceHREF(credentials, 'contentguards/core/rbac/', contentGuard)
|
||||
if (contentGuardHREF) {
|
||||
bodyContent.put('content_guard', "https://${pulpHost}${contentGuardHREF}")
|
||||
}
|
||||
}
|
||||
def postBody = JsonOutput.toJson(bodyContent)
|
||||
response = httpRequest authentication: credentials, url: "https://${pulpHost}${url}", httpMode: httpMode, requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:399"
|
||||
jsonResponse = readJSON text: response.content
|
||||
if (distribution) {
|
||||
@ -98,25 +140,6 @@ def distributePublication(
|
||||
}
|
||||
}
|
||||
|
||||
def waitForTaskCompletion(
|
||||
String credentials,
|
||||
String taskHREF,
|
||||
String pulpHost = '192.168.30.3'
|
||||
) {
|
||||
def status = ''
|
||||
def created_resources = []
|
||||
while (status != 'completed') {
|
||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true
|
||||
def jsonResponse = readJSON text: response.content
|
||||
status = jsonResponse.state
|
||||
if (status == 'completed') {
|
||||
created_resources = jsonResponse.created_resources
|
||||
}
|
||||
sleep(10)
|
||||
}
|
||||
return created_resources
|
||||
}
|
||||
|
||||
def getDistributionURL(
|
||||
String credentials,
|
||||
String resourceHREF,
|
||||
|
Reference in New Issue
Block a user