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
|
@ -1,36 +1,25 @@
|
||||||
import groovy.json.JsonOutput
|
import groovy.json.JsonOutput
|
||||||
|
|
||||||
def call() {
|
def getResourceHREF(
|
||||||
pipeline {
|
|
||||||
|
|
||||||
parameters {
|
|
||||||
string(
|
|
||||||
name: 'pulpHost',
|
|
||||||
description: 'Nom de domaine pour le serveur Pulp',
|
|
||||||
defaultValue: ''
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
def getResourceHREF(
|
|
||||||
String credentials,
|
String credentials,
|
||||||
String resourceEndpoint,
|
String resourceEndpoint,
|
||||||
String resourceName,
|
String resourceName,
|
||||||
// String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def response = httpRequest authentication: credentials, url: "https://${params.pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
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 jsonResponse = readJSON text: response.content
|
||||||
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
def resource = jsonResponse.results.find { it -> it.name == resourceName}
|
||||||
if (resource) {
|
if (resource) {
|
||||||
return resource.pulp_href
|
return resource.pulp_href
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
def waitForTaskCompletion(
|
def waitForTaskCompletion(
|
||||||
String credentials,
|
String credentials,
|
||||||
String taskHREF,
|
String taskHREF,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def status = ''
|
def status = ''
|
||||||
def created_resources = []
|
def created_resources = []
|
||||||
while (status != 'completed') {
|
while (status != 'completed') {
|
||||||
|
@ -45,13 +34,13 @@ def call() {
|
||||||
sleep(10)
|
sleep(10)
|
||||||
}
|
}
|
||||||
throw new Exception("Task failed:" + jsonResponse.error.description)
|
throw new Exception("Task failed:" + jsonResponse.error.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
def exportPackages(
|
def exportPackages(
|
||||||
String credentials,
|
String credentials,
|
||||||
List packages = [],
|
List packages = [],
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def exportTasks = []
|
def exportTasks = []
|
||||||
packages.each {
|
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 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"
|
||||||
|
@ -59,12 +48,12 @@ def call() {
|
||||||
exportTasks << jsonResponse['task']
|
exportTasks << jsonResponse['task']
|
||||||
}
|
}
|
||||||
return exportTasks
|
return exportTasks
|
||||||
}
|
}
|
||||||
|
|
||||||
def createRepository(
|
def createRepository(
|
||||||
String credentials,
|
String credentials,
|
||||||
String name,
|
String name,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def repositoryName = ["name": name]
|
def repositoryName = ["name": name]
|
||||||
def postBody = JsonOutput.toJson(repositoryName)
|
def postBody = JsonOutput.toJson(repositoryName)
|
||||||
|
@ -72,8 +61,8 @@ def call() {
|
||||||
def jsonResponse = readJSON text: response.content
|
def jsonResponse = readJSON text: response.content
|
||||||
return jsonResponse.pulp_href
|
return jsonResponse.pulp_href
|
||||||
|
|
||||||
}
|
}
|
||||||
def getRepositoryHREF(
|
def getRepositoryHREF(
|
||||||
String credentials,
|
String credentials,
|
||||||
String repository = 'Cadoles4MSE unstable'
|
String repository = 'Cadoles4MSE unstable'
|
||||||
) {
|
) {
|
||||||
|
@ -83,27 +72,27 @@ def call() {
|
||||||
} else {
|
} else {
|
||||||
return createRepository(credentials, repository)
|
return createRepository(credentials, repository)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def addToRepository(
|
def addToRepository(
|
||||||
String credentials,
|
String credentials,
|
||||||
List packagesHREF,
|
List packagesHREF,
|
||||||
String repositoryHREF,
|
String repositoryHREF,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
|
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
|
||||||
def postBody = JsonOutput.toJson(packagesHREFURL)
|
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 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
|
def jsonResponse = readJSON text: response.content
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
}
|
}
|
||||||
|
|
||||||
def publishRepository(
|
def publishRepository(
|
||||||
String credentials,
|
String credentials,
|
||||||
String repositoryHREF,
|
String repositoryHREF,
|
||||||
String signing_service = null,
|
String signing_service = null,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def postContent = ["repository": repositoryHREF, "simple": true]
|
def postContent = ["repository": repositoryHREF, "simple": true]
|
||||||
if (signing_service) {
|
if (signing_service) {
|
||||||
def signingServiceHREF = getResourceHREF(credentials, 'signing-services/', signing_service)
|
def signingServiceHREF = getResourceHREF(credentials, 'signing-services/', signing_service)
|
||||||
|
@ -115,16 +104,16 @@ def call() {
|
||||||
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 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
|
def jsonResponse = readJSON text: response.content
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
}
|
}
|
||||||
|
|
||||||
def distributePublication(
|
def distributePublication(
|
||||||
String credentials,
|
String credentials,
|
||||||
String publicationHREF,
|
String publicationHREF,
|
||||||
String distributionName,
|
String distributionName,
|
||||||
String basePath,
|
String basePath,
|
||||||
String contentGuard = null,
|
String contentGuard = null,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def httpMode = ''
|
def httpMode = ''
|
||||||
def url = ''
|
def url = ''
|
||||||
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
||||||
|
@ -151,17 +140,15 @@ def call() {
|
||||||
} else {
|
} else {
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getDistributionURL(
|
def getDistributionURL(
|
||||||
String credentials,
|
String credentials,
|
||||||
String resourceHREF,
|
String resourceHREF,
|
||||||
String pulpHost
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
||||||
def jsonResponse = readJSON text: response.content
|
def jsonResponse = readJSON text: response.content
|
||||||
println(jsonResponse)
|
println(jsonResponse)
|
||||||
return jsonResponse.base_url
|
return jsonResponse.base_url
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue