Automatiser la création des ressources en fonction du tag
Cadoles/Jenkins/pipeline/head There was a failure building this commit
Details
Cadoles/Jenkins/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
ad49ba869f
commit
c1cffc4d6f
|
@ -103,12 +103,15 @@ pipeline {
|
|||
)
|
||||
|
||||
// On publie chacun des paquets construits
|
||||
def repositoriesMapping = ['unstable': 'Cadoles4MSE unstable',
|
||||
'dev': 'Cadoles4MSE dev',
|
||||
'staging': 'Cadoles4MSE staging',
|
||||
'stable': 'Cadoles4MSE stable']
|
||||
def splittedTag = env.ref.split('/')
|
||||
def repositoryName = "${splittedTag[2]} ${splittedTag[1]}"
|
||||
def distributionName = repositoryName
|
||||
def basePath = repositoryName.replace(' ', '-')
|
||||
def product = splittedTag[2].split('-')[0]
|
||||
def contentGuardMapping = ['mse': 'mse_contentguard']
|
||||
def signingServiceMapping = ['mse': 'sign_deb_release']
|
||||
def credentials = '212d6dc7-f9a2-4d27-94d8-de7fc6cae0a1'
|
||||
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoriesMapping[result.env])
|
||||
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoryName)
|
||||
def exportTasks = pulp.exportPackages(credentials, result.packages)
|
||||
def pulpPackages = []
|
||||
exportTasks.each {
|
||||
|
@ -118,10 +121,8 @@ pipeline {
|
|||
}
|
||||
}
|
||||
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
|
||||
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF)
|
||||
def distributionName = repositoriesMapping[result.env]
|
||||
def base_path = distributionName.replaceAll(' ', '_')
|
||||
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, base_path)
|
||||
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF, signingServiceMapping.get(product))
|
||||
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, base_path, contentGuardMapping.get(product))
|
||||
def distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])
|
||||
|
||||
// On liste l'ensemble des paquets construits
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue