11 Commits

Author SHA1 Message Date
6fa3cdf8c1 Le paramètre doit être de type string
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-07-06 14:31:04 +02:00
ac4c65d930 gpg pour tous
All checks were successful
Cadoles/Jenkins/pipeline/head This commit looks good
2022-07-05 14:28:28 +02:00
69884d7384 change user pulp api
All checks were successful
Cadoles/Jenkins/pipeline/head This commit looks good
2022-06-15 14:33:06 +02:00
63af3c7121 retour en arrière
All checks were successful
Cadoles/Jenkins/pipeline/head This commit looks good
2022-06-07 11:22:21 +02:00
a31b64b5b6 test déclaration des paramètres de manière globale
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-06-07 10:50:23 +02:00
5112fc5d88 test déclaration des paramètres de manière globale
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-06-07 10:43:42 +02:00
c0bc85f860 correction variable
All checks were successful
Cadoles/Jenkins/pipeline/head This commit looks good
2022-06-03 15:18:47 +02:00
60769e3c68 ajout variable globale
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-06-03 15:05:29 +02:00
7d61382247 ajout variable globale
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-06-03 14:24:18 +02:00
d1757bc028 configuration nouvelle branche
All checks were successful
Cadoles/Jenkins/pipeline/head This commit looks good
2022-06-01 16:51:16 +02:00
0314146633 ajout groovy pour pulp.cadoles.com
Some checks failed
Cadoles/Jenkins/pipeline/head There was a failure building this commit
2022-06-01 16:29:02 +02:00
3 changed files with 167 additions and 12 deletions

7
Jenkinsfile vendored
View File

@ -1,4 +1,4 @@
@Library("cadoles@pipeline/empaquetage_pulp") _
@Library("cadoles@pipeline/packaging_pulp") _
pipeline {
@ -110,7 +110,7 @@ pipeline {
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 = 'jenkins-pulp-api-client'
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoryName)
def exportTasks = pulp.exportPackages(credentials, result.packages)
def pulpPackages = []
@ -121,7 +121,8 @@ pipeline {
}
}
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 distributionURL = pulp.getDistributionURL(credentials, distributionHREF[0])

View File

@ -4,7 +4,7 @@ def getResourceHREF(
String credentials,
String resourceEndpoint,
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, validResponseCodes: "200"
def jsonResponse = readJSON text: response.content
@ -18,7 +18,7 @@ def getResourceHREF(
def waitForTaskCompletion(
String credentials,
String taskHREF,
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
def status = ''
def created_resources = []
@ -39,10 +39,10 @@ def waitForTaskCompletion(
def exportPackages(
String credentials,
List packages = [],
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
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 jsonResponse = readJSON text: response.content
exportTasks << jsonResponse['task']
@ -53,7 +53,7 @@ def exportPackages(
def createRepository(
String credentials,
String name,
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
def repositoryName = ["name": name]
def postBody = JsonOutput.toJson(repositoryName)
@ -78,7 +78,7 @@ def addToRepository(
String credentials,
List packagesHREF,
String repositoryHREF,
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
def packagesHREFURL = ["add_content_units": packagesHREF.collect { "https://$pulpHost$it" }]
def postBody = JsonOutput.toJson(packagesHREFURL)
@ -91,7 +91,7 @@ def publishRepository(
String credentials,
String repositoryHREF,
String signing_service = null,
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
def postContent = ["repository": repositoryHREF, "simple": true]
if (signing_service) {
@ -112,7 +112,7 @@ def distributePublication(
String distributionName,
String basePath,
String contentGuard = null,
String pulpHost = '192.168.30.3'
String pulpHost = 'pulp.cadoles.com'
) {
def httpMode = ''
def url = ''
@ -145,7 +145,7 @@ def distributePublication(
def getDistributionURL(
String credentials,
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, validResponseCodes: "200"
def jsonResponse = readJSON text: response.content

154
vars/pulp.groovy.bak Normal file
View 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
}