Compare commits

...

42 Commits

Author SHA1 Message Date
Benjamin Bohard 6fa3cdf8c1 Le paramètre doit être de type string
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-07-06 14:31:04 +02:00
vfebvre ac4c65d930 gpg pour tous
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-07-05 14:28:28 +02:00
vfebvre 69884d7384 change user pulp api
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-06-15 14:33:06 +02:00
vfebvre 63af3c7121 retour en arrière
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-06-07 11:22:21 +02:00
vfebvre a31b64b5b6 test déclaration des paramètres de manière globale
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-06-07 10:50:23 +02:00
vfebvre 5112fc5d88 test déclaration des paramètres de manière globale
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-06-07 10:43:42 +02:00
vfebvre c0bc85f860 correction variable
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-06-03 15:18:47 +02:00
vfebvre 60769e3c68 ajout variable globale
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-06-03 15:05:29 +02:00
vfebvre 7d61382247 ajout variable globale
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-06-03 14:24:18 +02:00
vfebvre d1757bc028 configuration nouvelle branche
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-06-01 16:51:16 +02:00
vfebvre 0314146633 ajout groovy pour pulp.cadoles.com
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-06-01 16:29:02 +02:00
Benjamin Bohard 71f5fbfe78 Correction du code de retour d’une requête POST
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-29 09:54:05 +02:00
Benjamin Bohard 97abfb0ade Restreindre les codes retours valides
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-03-28 15:03:32 +02:00
Benjamin Bohard 44764866a8 Sortir de la boucle lorsqu’une tâche est en erreur
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-28 12:15:38 +02:00
Benjamin Bohard 1f6a71e0a9 Revert "Essai de chunk pour l’envoi des paquets"
Cadoles/Jenkins/pipeline/head This commit looks good Details
This reverts commit fad3f5fdcc.
2022-03-10 15:28:12 +01:00
Benjamin Bohard a819b3d9a1 Revert "Erreur de syntaxe"
This reverts commit 4153859453.
2022-03-10 15:28:04 +01:00
Benjamin Bohard 4153859453 Erreur de syntaxe
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-10 15:03:20 +01:00
Benjamin Bohard fad3f5fdcc Essai de chunk pour l’envoi des paquets
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-10 14:47:33 +01:00
Benjamin Bohard 8268ac2a0d Suppression des modifications pour debug
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-03-01 16:50:06 +01:00
Benjamin Bohard b4bb6dd7d6 Erreur de nom de paramètre pour la requête
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-01 16:39:06 +01:00
Benjamin Bohard 3897b60ef7 Debug erreur 400
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-01 16:30:14 +01:00
Benjamin Bohard 61b88898d8 Debug publication error
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-03-01 16:21:31 +01:00
Benjamin Bohard 493e9afd64 Mauvaise variable suite à réécriture
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-02-10 15:05:22 +01:00
Benjamin Bohard fe3c728823 mélange de dromadaire et de serpent
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 14:49:35 +01:00
Benjamin Bohard 5db4a47b13 paramètre manquant
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 14:27:49 +01:00
Benjamin Bohard 8b6228fe4a Typo
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 12:01:22 +01:00
Benjamin Bohard 672531fc36 Typo
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 11:18:39 +01:00
Benjamin Bohard 7be6603e81 Typo
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 10:51:09 +01:00
Benjamin Bohard c1cffc4d6f Automatiser la création des ressources en fonction du tag
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-10 10:26:05 +01:00
Benjamin Bohard ad49ba869f Typo
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-02-09 22:53:00 +01:00
Benjamin Bohard e16ccf8bf8 Erreur de syntaxe
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 21:48:40 +01:00
Benjamin Bohard 4dfdb53bad Distribution inconditionnelle
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 21:47:04 +01:00
Benjamin Bohard 331ba5fd6b Nettoyage
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 21:21:10 +01:00
Benjamin Bohard b7c0f4e2ab debug response
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 21:03:53 +01:00
Benjamin Bohard 2969fb2a7c debug return content
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 20:43:21 +01:00
Benjamin Bohard ab34e49bc1 Pas de tâche pour la création de dépôt
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 19:39:15 +01:00
Benjamin Bohard 5de4dfd4f8 Créer le dépôt si il n’existe pas
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 19:05:31 +01:00
Benjamin Bohard 1efbd7f5ee Erreur de syntaxe
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-09 10:02:00 +01:00
Benjamin Bohard 63c7b0b3a5 Changement de serveur pulp
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-08 09:28:59 +01:00
Benjamin Bohard f16e377911 Suppression de la boucle et du découpage de la sortie standard
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-08 09:18:19 +01:00
Benjamin Bohard 4ce857ef7c Ajustements
Cadoles/Jenkins/pipeline/head There was a failure building this commit Details
2022-02-08 08:33:09 +01:00
Benjamin Bohard 471b11740e Modèle de jenkinsfile pour envoi de paquet vers pulp
Cadoles/Jenkins/pipeline/head This commit looks good Details
2022-01-25 15:30:39 +01:00
4 changed files with 498 additions and 84 deletions

231
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,231 @@
@Library("cadoles@pipeline/packaging_pulp") _
pipeline {
agent {
label 'docker'
}
environment {
projectDir = "${env.project_name}_${env.BUILD_ID}"
}
triggers {
// Execute pipeline every day at 7h30 to prepare docker images
cron('30 7 * * 1-5')
}
stages {
stage("Prepare build environment") {
when {
anyOf {
triggeredBy cause: "UserIdCause", detail: "wpetit"
triggeredBy 'TimerTrigger'
}
}
steps {
script {
tamarin.prepareEnvironment()
}
}
}
stage("Package project") {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
script {
stage("Clone repository") {
checkout scm:
[
$class: 'GitSCM',
userRemoteConfigs: [[url: env.repository_url, credentialsId: 'jenkins-forge-ssh']],
branches: [[name: env.ref]],
extensions: [
[$class: 'RelativeTargetDirectory', relativeTargetDir: env.projectDir ],
[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: ''],
[$class: 'WipeWorkspace' ]
]
],
changelog: false,
poll: false
}
stage("Ensure packaging branch") {
dir(env.projectDir) {
sh 'git checkout "${packageBranch}"'
def commitOrRef = env.commit ? env.commit : env.ref
def branchesWithCommitOrRef = sh(script: "git branch --contains '${commitOrRef}'", returnStdout: true).split(' ')
if (branchesWithCommitOrRef.findAll{env.packageBranch.contains(it)}.any{true}) {
currentBuild.result = 'ABORTED'
error("La référence `${env.ref}` ne fait pas partie de la branche `${env.packageBranch}` !")
}
}
}
stage("Check [ci skip] in tag message") {
dir(env.projectDir) {
sh 'git checkout "${packageBranch}"'
def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ')
for (tag in commitTags) {
tag = tag.trim()
def tagMessage = sh(script: "git tag --format='%(subject)' -l '${tag}'", returnStdout: true).trim()
println("Tag '${tag}' message is: '${tagMessage}'")
if (tagMessage.contains('[ci skip]')) {
currentBuild.result = 'ABORTED'
error("Le message du tag '${tag}' contient le marqueur '[ci-skip]' !")
}
}
}
}
stage("Checkout ref") {
dir(env.projectDir) {
sh """
git checkout ${env.ref}
"""
}
}
stage("Build package") {
dir(env.projectDir) {
// On construit les paquets à partir des informations
// de contexte provenant de CPKG et du webhook
def result = tamarin.buildPackageWithCPKG(
env.packageProfile ? env.packageProfile : "debian",
env.packageArch ? env.packageArch : "",
env.packageBranch ? env.packageBranch : "",
env.baseImage ? env.baseImage : ""
)
// On publie chacun des paquets construits
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 = 'jenkins-pulp-api-client'
def repositoryHREF = pulp.getRepositoryHREF(credentials, repositoryName)
def exportTasks = pulp.exportPackages(credentials, result.packages)
def pulpPackages = []
exportTasks.each {
def created_resources = pulp.waitForTaskCompletion(credentials, it)
for (created_resource in created_resources) {
pulpPackages << created_resource
}
}
pulp.addToRepository(credentials, pulpPackages, repositoryHREF)
// 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])
// On liste l'ensemble des paquets construits
def publishedPackages = result.packages.collect { p ->
def file = new File(p)
return "- Paquet `${file.getName()}`, Dépôt `${result.env}`, Distribution `${result.distrib}`, URL `${distributionURL}`"
}
// On notifie le canal Rocket.Chat de la publication des paquets
rocketSend (
avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
message: """
Les paquets suivants ont été publiés pour le projet ${env.project_name}:
${publishedPackages.join('\n')}
[Visualiser le job](${env.RUN_DISPLAY_URL})
@${env.sender_login}
""".stripIndent(),
rawMessage: true,
attachments: lolops.getRandomDeliveryAttachment()
)
if (env.testPackageInstall != 'yes') {
println "Test d'intallation des paquets désactivé."
return
}
// On essaye de trouver un template de VM compatible
// avec la distribution cible de la construction
def vmTemplate = findMatchingVMTemplate(result.distrib)
if (vmTemplate == null) {
println "Aucun template de VM n'a été trouvé correspondant à la distribution `${result.distrib}`."
return
}
// Pour chaque paquets construits...
result.packages.each { p ->
def packageFullName = new File(p).getName()
def packageRepository = result.distrib.split('-')[1] + '-' + result.env
def packageNameParts = packageFullName.split('_')
def packageName = packageNameParts[0]
def packageVersion = packageNameParts[1]
stage("Test package '${packageName}' installation") {
build job: 'Test de paquet Debian', wait: false, parameters: [
[$class: 'StringParameterValue', name: 'packageName', value: packageName],
[$class: 'StringParameterValue', name: 'packageVersion', value: packageVersion],
[$class: 'StringParameterValue', name: 'packageRepository', value: packageRepository],
[$class: 'StringParameterValue', name: 'vmTemplate', value: vmTemplate]
]
}
}
}
}
}
}
post {
always {
sh "rm -rf '${env.projectDir}'"
}
}
}
}
}
// Cette fonction fait un simple "mapping"
// entre les distributions cibles des paquets et
// les templates de VM disponibles sur l'OpenNebula
def findMatchingVMTemplate(String distrib) {
def vmTemplatesMap = [
'eole-2.7.0': 'eolebase-2.7.0-cadoles',
'eole-2.6.2': 'eolebase-2.6.2-cadoles'
]
return vmTemplatesMap.get(distrib, null)
}
def waitForPackages(String tagRef, buildResults) {
def packageVersion = tagRef.split('/')[3];
def packageDistrib = env.packageBranch.split('/')[2];
buildResults.each { r ->
def distrib = "${packageDistrib}-${r.env}"
r.packages.each { p ->
def file = new File(p)
def fileNameParts = file.getName().take(file.getName().lastIndexOf('.')).split('_')
def packageName = fileNameParts[0]
def packageArch = fileNameParts[2]
debian.waitForRepoPackage(packageName, [
baseURL: 'https://vulcain.cadoles.com',
distrib: distrib,
component: 'main',
type: 'binary',
arch: packageArch,
expectedVersion: packageVersion
])
}
}
}

View File

@ -1,43 +1,88 @@
import groovy.json.JsonOutput 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( def exportPackages(
String credentials, String credentials,
List packages = [], List packages = [],
String pulpHost = 'pulp.bbohard.lan' 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, responseHandle: 'NONE', 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"
jsonResponse = readJSON text: response.content def jsonResponse = readJSON text: response.content
println(jsonResponse)
exportTasks << jsonResponse['task'] exportTasks << jsonResponse['task']
} }
return exportTasks 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( def getRepositoryHREF(
String credentials, String credentials,
String repositoryLevel = 'dev', String repository = 'Cadoles4MSE unstable'
String pulpHost = 'pulp.bbohard.lan'
) { ) {
def repositoriesMapping = ['dev': 'Cadoles4MSE'] def repositoryHREF = getResourceHREF(credentials, 'repositories/deb/apt/', repository)
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/repositories/deb/apt/", httpMode: 'GET', ignoreSslErrors: true if (repositoryHREF) {
def jsonResponse = readJSON text: response.content return repositoryHREF
println(jsonResponse) } else {
def repositories = jsonResponse.results return createRepository(credentials, repository)
def repositoryHREF = repositories.find { it -> it['name'] == repositoriesMapping[repositoryLevel] } }
return repositoryHREF.pulp_href
} }
def addToRepository( def addToRepository(
String credentials, String credentials,
List packagesHREF, List packagesHREF,
String repositoryHREF, String repositoryHREF,
String pulpHost = 'pulp.bbohard.lan' 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:599" 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)
} }
@ -45,12 +90,19 @@ def addToRepository(
def publishRepository( def publishRepository(
String credentials, String credentials,
String repositoryHREF, String repositoryHREF,
String pulpHost = 'pulp.bbohard.lan' String signing_service = null,
String pulpHost = 'pulp.cadoles.com'
) { ) {
def postBody = JsonOutput.toJson(["repository": repositoryHREF, "simple": true]) def postContent = ["repository": repositoryHREF, "simple": true]
def response = httpRequest authentication: credentials, url: "https://${pulpHost}/pulp/api/v3/publications/deb/apt/", httpMode: 'POST', requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: 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 def jsonResponse = readJSON text: response.content
println(jsonResponse)
return waitForTaskCompletion(credentials, jsonResponse.task) return waitForTaskCompletion(credentials, jsonResponse.task)
} }
@ -59,26 +111,30 @@ def distributePublication(
String publicationHREF, String publicationHREF,
String distributionName, String distributionName,
String basePath, String basePath,
String pulpHost = 'pulp.bbohard.lan', String contentGuard = null,
String contentGuard = null String pulpHost = 'pulp.cadoles.com'
) { ) {
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]
response = httpRequest authentication: credentials, url: "https://${pulpHost}${url}", httpMode: httpMode, requestBody: postBody, contentType: 'APPLICATION_JSON', ignoreSslErrors: true, validResponseCodes: "100:599" 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 jsonResponse = readJSON text: response.content
if (distribution) { if (distributionHREF) {
waitForTaskCompletion(credentials, jsonResponse.task) waitForTaskCompletion(credentials, jsonResponse.task)
return [url] return [url]
} else { } else {
@ -86,31 +142,12 @@ def distributePublication(
} }
} }
def waitForTaskCompletion(
String credentials,
String taskHREF,
String pulpHost = 'pulp.bbohard.lan'
) {
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,
String pulpHost = 'pulp.bbohard.lan' 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
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
}

View File

@ -7,46 +7,38 @@ def buildPackageWithCPKG(
Boolean forceRebuild = false Boolean forceRebuild = false
) { ) {
def builds = [] def result = [:]
// Retrieve commit tags // Retrieve commit tags
def commitTags = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true).split(' ') def commitTag = sh(script: 'git describe --exact-match --abbrev=0', returnStdout: true)
if (commitTags.length == 0) { if (commitTag == '') {
error 'No build build tags on last commit' error 'No build build tags on last commit'
} }
// For each tags // Split tag to retrieve context informations
for (tag in commitTags) { def tagParts = commitTag.split('/')
def packageEnv = tagParts[1]
def packageDistrib = tagParts[2]
def packageVersion = tagParts[3]
// Split tag to retrieve context informations // Create .tamarinrc file
def tagParts = tag.split('/') def tamarinrc = """
def packageEnv = tagParts[1] project_version=${packageVersion}
def packageDistrib = tagParts[2] no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
def packageVersion = tagParts[3] """.stripIndent()
writeFile file: '.tamarinrc', text: tamarinrc
// Create .tamarinrc file sh "rm -rf ${destDir}/*"
def tamarinrc = """
project_version=${packageVersion}
no_version_suffix=${ packageEnv == 'stable' || packageEnv == 'staging' ? 'yes' : 'no' }
""".stripIndent()
writeFile file: '.tamarinrc', text: tamarinrc
sh "rm -rf ${destDir}/*"
stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") { stage("Build ${packageEnv} package (version ${packageVersion}) for ${packageDistrib}") {
def result = [:] result.put('tag', commitTag)
result.put('tag', tag) result.put('env', packageEnv)
result.put('env', packageEnv) result.put('version', packageVersion)
result.put('version', packageVersion) result.put('distrib', packageDistrib)
result.put('distrib', packageDistrib) def packages = buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild)
def packages = buildPackage(packageProfile, packageArch, baseImage, destDir, forceRebuild) result.put('packages', packages)
result.put('packages', packages)
builds << result
}
} }
return result
return builds
} }
@ -129,4 +121,4 @@ def buildDockerImage() {
def imageTag = "${safeJobName}-${env.BUILD_ID}" def imageTag = "${safeJobName}-${env.BUILD_ID}"
return docker.build("tamarin:${imageTag}", ".") return docker.build("tamarin:${imageTag}", ".")
} }
} }