Compare commits
16 Commits
4153859453
...
pipeline/p
Author | SHA1 | Date | |
---|---|---|---|
6fa3cdf8c1 | |||
ac4c65d930 | |||
69884d7384 | |||
63af3c7121 | |||
a31b64b5b6 | |||
5112fc5d88 | |||
c0bc85f860 | |||
60769e3c68 | |||
7d61382247 | |||
d1757bc028 | |||
0314146633 | |||
71f5fbfe78 | |||
97abfb0ade | |||
44764866a8 | |||
1f6a71e0a9 | |||
a819b3d9a1 |
7
Jenkinsfile
vendored
7
Jenkinsfile
vendored
@ -1,4 +1,4 @@
|
|||||||
@Library("cadoles@pipeline/empaquetage_pulp") _
|
@Library("cadoles@pipeline/packaging_pulp") _
|
||||||
|
|
||||||
pipeline {
|
pipeline {
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ pipeline {
|
|||||||
def product = splittedTag[2].split('-')[0]
|
def product = splittedTag[2].split('-')[0]
|
||||||
def contentGuardMapping = ['mse': 'mse_contentguard']
|
def contentGuardMapping = ['mse': 'mse_contentguard']
|
||||||
def signingServiceMapping = ['mse': 'sign_deb_release']
|
def signingServiceMapping = ['mse': 'sign_deb_release']
|
||||||
def credentials = '212d6dc7-f9a2-4d27-94d8-de7fc6cae0a1'
|
def credentials = 'jenkins-pulp-api-client'
|
||||||
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoryName)
|
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoryName)
|
||||||
def exportTasks = pulp.exportPackages(credentials, result.packages)
|
def exportTasks = pulp.exportPackages(credentials, result.packages)
|
||||||
def pulpPackages = []
|
def pulpPackages = []
|
||||||
@ -121,7 +121,8 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
|
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
|
||||||
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF, signingServiceMapping.get(product))
|
// def publicationHREF = pulp.publishRepository(credentials, repositoryHREF, signingServiceMapping.get(product))
|
||||||
|
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF, 'sign_deb_release')
|
||||||
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, basePath, contentGuardMapping.get(product))
|
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, basePath, contentGuardMapping.get(product))
|
||||||
def distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])
|
def distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])
|
||||||
|
|
||||||
|
@ -4,9 +4,9 @@ def getResourceHREF(
|
|||||||
String credentials,
|
String credentials,
|
||||||
String resourceEndpoint,
|
String resourceEndpoint,
|
||||||
String resourceName,
|
String resourceName,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/${resourceEndpoint}", httpMode: 'GET', ignoreSslErrors: true
|
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) {
|
||||||
@ -18,30 +18,32 @@ def getResourceHREF(
|
|||||||
def waitForTaskCompletion(
|
def waitForTaskCompletion(
|
||||||
String credentials,
|
String credentials,
|
||||||
String taskHREF,
|
String taskHREF,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def status = ''
|
def status = ''
|
||||||
def created_resources = []
|
def created_resources = []
|
||||||
while (status != 'completed') {
|
while (status != 'completed') {
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true
|
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${taskHREF}", httpMode: 'GET', ignoreSslErrors: true, validResponseCodes: "200"
|
||||||
def jsonResponse = readJSON text: response.content
|
def jsonResponse = readJSON text: response.content
|
||||||
status = jsonResponse.state
|
status = jsonResponse.state
|
||||||
if (status == 'completed') {
|
if (status == 'completed') {
|
||||||
created_resources = jsonResponse.created_resources
|
return jsonResponse.created_resources
|
||||||
|
} else if (!(status in ['running','waiting'])) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
sleep(10)
|
sleep(10)
|
||||||
}
|
}
|
||||||
return created_resources
|
throw new Exception("Task failed:" + jsonResponse.error.description)
|
||||||
}
|
}
|
||||||
|
|
||||||
def exportPackages(
|
def exportPackages(
|
||||||
String credentials,
|
String credentials,
|
||||||
List packages = [],
|
List packages = [],
|
||||||
String pulpHost = '192.168.30.3'
|
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", customHeaders: [[name: 'Transfer-Encoding', value: 'chunked']], timeout: 900, uploadFile: "${it}"
|
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
|
def jsonResponse = readJSON text: response.content
|
||||||
exportTasks << jsonResponse['task']
|
exportTasks << jsonResponse['task']
|
||||||
}
|
}
|
||||||
@ -51,11 +53,11 @@ def exportPackages(
|
|||||||
def createRepository(
|
def createRepository(
|
||||||
String credentials,
|
String credentials,
|
||||||
String name,
|
String name,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def repositoryName = ["name": name]
|
def repositoryName = ["name": name]
|
||||||
def postBody = JsonOutput.toJson(repositoryName)
|
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: "100:399"
|
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
|
def jsonResponse = readJSON text: response.content
|
||||||
return jsonResponse.pulp_href
|
return jsonResponse.pulp_href
|
||||||
|
|
||||||
@ -76,11 +78,11 @@ def addToRepository(
|
|||||||
String credentials,
|
String credentials,
|
||||||
List packagesHREF,
|
List packagesHREF,
|
||||||
String repositoryHREF,
|
String repositoryHREF,
|
||||||
String pulpHost = '192.168.30.3'
|
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: "100:399"
|
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)
|
||||||
}
|
}
|
||||||
@ -89,7 +91,7 @@ def publishRepository(
|
|||||||
String credentials,
|
String credentials,
|
||||||
String repositoryHREF,
|
String repositoryHREF,
|
||||||
String signing_service = null,
|
String signing_service = null,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def postContent = ["repository": repositoryHREF, "simple": true]
|
def postContent = ["repository": repositoryHREF, "simple": true]
|
||||||
if (signing_service) {
|
if (signing_service) {
|
||||||
@ -99,7 +101,7 @@ def publishRepository(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def postBody = JsonOutput.toJson(postContent)
|
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 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)
|
||||||
}
|
}
|
||||||
@ -110,7 +112,7 @@ def distributePublication(
|
|||||||
String distributionName,
|
String distributionName,
|
||||||
String basePath,
|
String basePath,
|
||||||
String contentGuard = null,
|
String contentGuard = null,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def httpMode = ''
|
def httpMode = ''
|
||||||
def url = ''
|
def url = ''
|
||||||
@ -130,7 +132,7 @@ def distributePublication(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
def postBody = JsonOutput.toJson(bodyContent)
|
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"
|
response = httpRequest authentication: credentials, url: "https://${pulpHost}${url}", httpMode: httpMode, requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "202"
|
||||||
jsonResponse = readJSON text: response.content
|
jsonResponse = readJSON text: response.content
|
||||||
if (distributionHREF) {
|
if (distributionHREF) {
|
||||||
waitForTaskCompletion(credentials, jsonResponse.task)
|
waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
@ -143,9 +145,9 @@ def distributePublication(
|
|||||||
def getDistributionURL(
|
def getDistributionURL(
|
||||||
String credentials,
|
String credentials,
|
||||||
String resourceHREF,
|
String resourceHREF,
|
||||||
String pulpHost = '192.168.30.3'
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
) {
|
) {
|
||||||
def response = httpRequest authentication: credentials, url: "https://${pulpHost}${resourceHREF}", httpMode: 'GET', ignoreSslErrors: true
|
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
|
||||||
|
154
vars/pulp.groovy.bak
Normal file
154
vars/pulp.groovy.bak
Normal file
@ -0,0 +1,154 @@
|
|||||||
|
import groovy.json.JsonOutput
|
||||||
|
|
||||||
|
def getResourceHREF(
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
def waitForTaskCompletion(
|
||||||
|
String credentials,
|
||||||
|
String taskHREF,
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
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 exportPackages(
|
||||||
|
String credentials,
|
||||||
|
List packages = [],
|
||||||
|
String pulpHost = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
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 = 'pulp.cadoles.com'
|
||||||
|
) {
|
||||||
|
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 = '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
|
||||||
|
}
|
Reference in New Issue
Block a user