retour en arrière
Cadoles/Jenkins/pipeline/head This commit looks good
Details
Cadoles/Jenkins/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a31b64b5b6
commit
63af3c7121
309
vars/pulp.groovy
309
vars/pulp.groovy
|
@ -1,167 +1,154 @@
|
||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
|
|
||||||
def call() {
|
def getResourceHREF(
|
||||||
pipeline {
|
String credentials,
|
||||||
|
String resourceEndpoint,
|
||||||
|
String resourceName,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
||||||
|
def jsonResponse = readJSON text: response.content
|
||||||
|
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
||||||
|
if (resource) {
|
||||||
|
return resource.pulp_href
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
parameters {
|
def waitForTaskCompletion(
|
||||||
string(
|
String credentials,
|
||||||
name: 'pulpHost',
|
String taskHREF,
|
||||||
description: 'Nom de domaine pour le serveur Pulp',
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
defaultValue: ''
|
) {
|
||||||
)
|
def status = ''
|
||||||
}
|
def created_resources = []
|
||||||
|
while (status != 'completed') {
|
||||||
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
||||||
|
def jsonResponse = readJSON text: response.content
|
||||||
|
status = jsonResponse.state
|
||||||
|
if (status == 'completed') {
|
||||||
|
return jsonResponse.created_resources
|
||||||
|
} else if (!(status in ['running','waiting'])) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sleep(10)
|
||||||
|
}
|
||||||
|
throw new Exception("Task failed:" + jsonResponse.error.description)
|
||||||
|
}
|
||||||
|
|
||||||
def getResourceHREF(
|
def exportPackages(
|
||||||
String credentials,
|
String credentials,
|
||||||
String resourceEndpoint,
|
List packages = [],
|
||||||
String resourceName,
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
// String pulpHost
|
) {
|
||||||
) {
|
def exportTasks = []
|
||||||
def response = httpRequest authentication: credentials, url: "https://${params.pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
packages.each {
|
||||||
def jsonResponse = readJSON text: response.content
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/content/deb/packages/", httpMode: 'POST', ignoreSslErrors: true, multipartName: "file", timeout: 900, uploadFile: "${it}", validResponseCodes: "202"
|
||||||
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
def jsonResponse = readJSON text: response.content
|
||||||
if (resource) {
|
exportTasks << jsonResponse['task']
|
||||||
return resource.pulp_href
|
}
|
||||||
}
|
return exportTasks
|
||||||
return null
|
}
|
||||||
}
|
|
||||||
|
def createRepository(
|
||||||
def waitForTaskCompletion(
|
String credentials,
|
||||||
String credentials,
|
String name,
|
||||||
String taskHREF,
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
String pulpHost
|
) {
|
||||||
) {
|
def repositoryName = ["name": name]
|
||||||
def status = ''
|
def postBody = JsonOutput.toJson(repositoryName)
|
||||||
def created_resources = []
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/repositories/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "201"
|
||||||
while (status != 'completed') {
|
def jsonResponse = readJSON text: response.content
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
return jsonResponse.pulp_href
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
status = jsonResponse.state
|
}
|
||||||
if (status == 'completed') {
|
def getRepositoryHREF(
|
||||||
return jsonResponse.created_resources
|
String credentials,
|
||||||
} else if (!(status in ['running','waiting'])) {
|
String repository = 'Cadoles4MSE unstable'
|
||||||
break
|
) {
|
||||||
}
|
def repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
|
||||||
sleep(10)
|
if (repositoryHREF) {
|
||||||
}
|
return repositoryHREF
|
||||||
throw new Exception("Task failed:" + jsonResponse.error.description)
|
} else {
|
||||||
}
|
return createRepository(credentials, repository)
|
||||||
|
|
||||||
def exportPackages(
|
|
||||||
String credentials,
|
|
||||||
List packages = [],
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
def exportTasks = []
|
|
||||||
packages.each {
|
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/content/deb/packages/", httpMode: 'POST', ignoreSslErrors: true, multipartName: "file", timeout: 900, uploadFile: "${it}", validResponseCodes: "202"
|
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
exportTasks << jsonResponse['task']
|
|
||||||
}
|
|
||||||
return exportTasks
|
|
||||||
}
|
|
||||||
|
|
||||||
def createRepository(
|
|
||||||
String credentials,
|
|
||||||
String name,
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
def repositoryName = ["name": name]
|
|
||||||
def postBody = JsonOutput.toJson(repositoryName)
|
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/repositories/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "201"
|
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
return jsonResponse.pulp_href
|
|
||||||
|
|
||||||
}
|
|
||||||
def getRepositoryHREF(
|
|
||||||
String credentials,
|
|
||||||
String repository = 'Cadoles4MSE unstable'
|
|
||||||
) {
|
|
||||||
def repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
|
|
||||||
if (repositoryHREF) {
|
|
||||||
return repositoryHREF
|
|
||||||
} else {
|
|
||||||
return createRepository(credentials, repository)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def addToRepository(
|
|
||||||
String credentials,
|
|
||||||
List packagesHREF,
|
|
||||||
String repositoryHREF,
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
|
|
||||||
def postBody = JsonOutput.toJson(packagesHREFURL)
|
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${repositoryHREF}modify/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "202"
|
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
||||||
}
|
|
||||||
|
|
||||||
def publishRepository(
|
|
||||||
String credentials,
|
|
||||||
String repositoryHREF,
|
|
||||||
String signing_service = null,
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
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, validResponseCodes: "202"
|
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
||||||
}
|
|
||||||
|
|
||||||
def distributePublication(
|
|
||||||
String credentials,
|
|
||||||
String publicationHREF,
|
|
||||||
String distributionName,
|
|
||||||
String basePath,
|
|
||||||
String contentGuard = null,
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
def httpMode = ''
|
|
||||||
def url = ''
|
|
||||||
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
|
||||||
if (distributionHREF) {
|
|
||||||
httpMode = 'PUT'
|
|
||||||
url = distributionHREF
|
|
||||||
} else {
|
|
||||||
httpMode = 'POST'
|
|
||||||
url = '/pulp/api/v3/distributions/deb/apt/'
|
|
||||||
}
|
|
||||||
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: "202"
|
|
||||||
jsonResponse = readJSON text: response.content
|
|
||||||
if (distributionHREF) {
|
|
||||||
waitForTaskCompletion(credentials, jsonResponse.task)
|
|
||||||
return [url]
|
|
||||||
} else {
|
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def getDistributionURL(
|
|
||||||
String credentials,
|
|
||||||
String resourceHREF,
|
|
||||||
String pulpHost
|
|
||||||
) {
|
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
println(jsonResponse)
|
|
||||||
return jsonResponse.base_url
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def addToRepository(
|
||||||
|
String credentials,
|
||||||
|
List packagesHREF,
|
||||||
|
String repositoryHREF,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
|
||||||
|
def postBody = JsonOutput.toJson(packagesHREFURL)
|
||||||
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${repositoryHREF}modify/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "202"
|
||||||
|
def jsonResponse = readJSON text: response.content
|
||||||
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
|
}
|
||||||
|
|
||||||
|
def publishRepository(
|
||||||
|
String credentials,
|
||||||
|
String repositoryHREF,
|
||||||
|
String signing_service = null,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
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, validResponseCodes: "202"
|
||||||
|
def jsonResponse = readJSON text: response.content
|
||||||
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
|
}
|
||||||
|
|
||||||
|
def distributePublication(
|
||||||
|
String credentials,
|
||||||
|
String publicationHREF,
|
||||||
|
String distributionName,
|
||||||
|
String basePath,
|
||||||
|
String contentGuard = null,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
def httpMode = ''
|
||||||
|
def url = ''
|
||||||
|
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
||||||
|
if (distributionHREF) {
|
||||||
|
httpMode = 'PUT'
|
||||||
|
url = distributionHREF
|
||||||
|
} else {
|
||||||
|
httpMode = 'POST'
|
||||||
|
url = '/pulp/api/v3/distributions/deb/apt/'
|
||||||
|
}
|
||||||
|
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: "202"
|
||||||
|
jsonResponse = readJSON text: response.content
|
||||||
|
if (distributionHREF) {
|
||||||
|
waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
|
return [url]
|
||||||
|
} else {
|
||||||
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getDistributionURL(
|
||||||
|
String credentials,
|
||||||
|
String resourceHREF,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
||||||
|
def jsonResponse = readJSON text: response.content
|
||||||
|
println(jsonResponse)
|
||||||
|
return jsonResponse.base_url
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue