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
|
// On publie chacun des paquets construits
|
||||||
def repositoriesMapping = ['unstable': 'Cadoles4MSE unstable',
|
def splittedTag = env.ref.split('/')
|
||||||
'dev': 'Cadoles4MSE dev',
|
def repositoryName = "${splittedTag[2]} ${splittedTag[1]}"
|
||||||
'staging': 'Cadoles4MSE staging',
|
def distributionName = repositoryName
|
||||||
'stable': 'Cadoles4MSE stable']
|
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 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 exportTasks = pulp.exportPackages(credentials, result.packages)
|
||||||
def pulpPackages = []
|
def pulpPackages = []
|
||||||
exportTasks.each {
|
exportTasks.each {
|
||||||
|
@ -118,10 +121,8 @@ pipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
|
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
|
||||||
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF)
|
def publicationHREF = pulp.publishRepository(credentials, repositoryHREF, signingServiceMapping.get(product))
|
||||||
def distributionName = repositoriesMapping[result.env]
|
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, base_path, contentGuardMapping.get(product))
|
||||||
def base_path = distributionName.replaceAll(' ', '_')
|
|
||||||
def distributionHREF = pulp.distributePublication(credentials, publicationHREF[0], distributionName, base_path)
|
|
||||||
def distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])
|
def distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])
|
||||||
|
|
||||||
// On liste l'ensemble des paquets construits
|
// On liste l'ensemble des paquets construits
|
||||||
|
|
|
@ -1,5 +1,38 @@
|
||||||
import groovy.json.JsonOutput
|
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(
|
def exportPackages(
|
||||||
String credentials,
|
String credentials,
|
||||||
List packages = [],
|
List packages = [],
|
||||||
|
@ -31,12 +64,9 @@ def getRepositoryHREF(
|
||||||
String repository = 'Cadoles4MSE unstable',
|
String repository = 'Cadoles4MSE unstable',
|
||||||
String pulpHost = '192.168.30.3'
|
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 repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
|
||||||
def jsonResponse = readJSON text: response.content
|
|
||||||
def repositories = jsonResponse.results
|
|
||||||
def repositoryHREF = repositories.find { it -> it['name'] == repository }
|
|
||||||
if (repositoryHREF) {
|
if (repositoryHREF) {
|
||||||
return repositoryHREF.pulp_href
|
return repositoryHREF
|
||||||
} else {
|
} else {
|
||||||
return createRepository(credentials, repository)
|
return createRepository(credentials, repository)
|
||||||
}
|
}
|
||||||
|
@ -58,9 +88,17 @@ def addToRepository(
|
||||||
def publishRepository(
|
def publishRepository(
|
||||||
String credentials,
|
String credentials,
|
||||||
String repositoryHREF,
|
String repositoryHREF,
|
||||||
|
String signing_service = null
|
||||||
String pulpHost = '192.168.30.3'
|
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 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
|
def jsonResponse = readJSON text: response.content
|
||||||
return waitForTaskCompletion(credentials, jsonResponse.task)
|
return waitForTaskCompletion(credentials, jsonResponse.task)
|
||||||
|
@ -71,23 +109,27 @@ def distributePublication(
|
||||||
String publicationHREF,
|
String publicationHREF,
|
||||||
String distributionName,
|
String distributionName,
|
||||||
String basePath,
|
String basePath,
|
||||||
String pulpHost = '192.168.30.3',
|
|
||||||
String contentGuard = null
|
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 httpMode = ''
|
||||||
def url = ''
|
def url = ''
|
||||||
def distribution = jsonResponse.results.find { it -> it.name == distributionName}
|
def distributionHREF = getResourceHREF(credentials, 'distributions/deb/apt/', distributionName)
|
||||||
if (distribution) {
|
if (distributionHREF) {
|
||||||
httpMode = 'PUT'
|
httpMode = 'PUT'
|
||||||
url = distribution.pulp_href
|
url = distributionHREF
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
httpMode = 'POST'
|
httpMode = 'POST'
|
||||||
url = '/pulp/api/v3/distributions/deb/apt/'
|
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"
|
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
|
jsonResponse = readJSON text: response.content
|
||||||
if (distribution) {
|
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(
|
def getDistributionURL(
|
||||||
String credentials,
|
String credentials,
|
||||||
String resourceHREF,
|
String resourceHREF,
|
||||||
|
|
Loading…
Reference in New Issue