2022-08-08 16:56:01 +02:00
|
|
|
|
// Pipeline de construction des images Docker des services Zéphir
|
|
|
|
|
def call() {
|
|
|
|
|
def buildTag
|
2022-09-26 08:44:28 +02:00
|
|
|
|
def gitEmail = params.gitEmail ? params.gitEmail : 'jenkins@cadoles.com'
|
|
|
|
|
def gitUsername = params.gitUsername ? params.gitUsername : 'Jenkins'
|
2022-08-08 16:56:01 +02:00
|
|
|
|
|
|
|
|
|
pipeline {
|
|
|
|
|
|
|
|
|
|
agent any
|
|
|
|
|
|
|
|
|
|
environment {
|
|
|
|
|
projectDir = "${env.project_name}_${env.BUILD_ID}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
triggers {
|
|
|
|
|
// Execute pipeline every day at 7h30 to prepare docker images
|
|
|
|
|
cron('30 7 * * 1-5')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parameters {
|
|
|
|
|
string(
|
|
|
|
|
name: 'targetUrl',
|
|
|
|
|
description: 'URL cible pour le dépôt de fichier',
|
2022-08-11 12:29:23 +02:00
|
|
|
|
defaultValue: 'https://nextcloud.cadoles.com/nextcloud'
|
2022-08-08 16:56:01 +02:00
|
|
|
|
)
|
|
|
|
|
string(
|
|
|
|
|
name: 'targetFolder',
|
|
|
|
|
description: 'Répertoire racine cible partagé avec l’utilisateur',
|
2022-08-11 12:35:37 +02:00
|
|
|
|
defaultValue: 'Cadoles Formation'
|
2022-08-08 16:56:01 +02:00
|
|
|
|
)
|
|
|
|
|
string(
|
|
|
|
|
name: 'credentialsId',
|
|
|
|
|
description: "Identifiant du compte de type login/mot de passe",
|
2022-08-11 11:06:32 +02:00
|
|
|
|
defaultValue: 'nextcloud-user-for-formation-documents'
|
2022-08-08 16:56:01 +02:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stages {
|
|
|
|
|
|
|
|
|
|
stage("Prepare build environment") {
|
|
|
|
|
when {
|
|
|
|
|
anyOf {
|
|
|
|
|
triggeredBy cause: "UserIdCause", detail: "bbohard"
|
|
|
|
|
triggeredBy 'TimerTrigger'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
tamarin.prepareEnvironment()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stage("Build doc") {
|
|
|
|
|
when {
|
|
|
|
|
not {
|
|
|
|
|
triggeredBy 'TimerTrigger'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
steps {
|
|
|
|
|
script {
|
|
|
|
|
stage("Check tag") {
|
|
|
|
|
buildTag = env.ref
|
|
|
|
|
if (!buildTag.startsWith('build/')) {
|
|
|
|
|
currentBuild.result= 'ABORTED'
|
|
|
|
|
error("La référence `${buildTag}` n’est pas une demande de paquet valide.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
stage("Clone repository") {
|
|
|
|
|
checkout scm:
|
|
|
|
|
[
|
|
|
|
|
$class: 'GitSCM',
|
2022-08-11 12:01:32 +02:00
|
|
|
|
userRemoteConfigs: [[url: env.repository_url, credentialsId: 'jenkins-forge-ssh']],
|
2022-08-08 16:56:01 +02:00
|
|
|
|
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("Checkout ref") {
|
|
|
|
|
dir(env.projectDir) {
|
|
|
|
|
sh """
|
|
|
|
|
git checkout ${env.ref}
|
|
|
|
|
"""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
stage("Compile document") {
|
|
|
|
|
dir(env.projectDir) {
|
|
|
|
|
def date = new Date()
|
|
|
|
|
def dateTag = date.format('yyyyMMdd')
|
|
|
|
|
def splittedTag = env.ref.split('/')
|
|
|
|
|
def docProfile = splittedTag[1]
|
|
|
|
|
withCredentials([
|
|
|
|
|
usernamePassword(
|
|
|
|
|
credentialsId: params.credentialsId,
|
|
|
|
|
usernameVariable: "NEXTCLOUD_USER",
|
|
|
|
|
passwordVariable: "NEXTCLOUD_PASSWORD"
|
|
|
|
|
)
|
|
|
|
|
]) {
|
2022-08-11 11:53:32 +02:00
|
|
|
|
targetFolder = targetFolder.replace(' ', '%20')
|
2022-08-08 16:56:01 +02:00
|
|
|
|
def rootFolder = "${params.targetUrl}/remote.php/dav/files/${NEXTCLOUD_USER}/${targetFolder}"
|
|
|
|
|
def projectName = env.project_name
|
|
|
|
|
def destFolder = "${projectName}/${docProfile}"
|
2022-08-11 11:06:32 +02:00
|
|
|
|
def result = tamarin.compileDoc(env.buildProfile)
|
2022-09-26 08:44:28 +02:00
|
|
|
|
if(result.size() == 0) {
|
|
|
|
|
error('No artefact produced')
|
|
|
|
|
}
|
2022-08-08 16:56:01 +02:00
|
|
|
|
println(result)
|
|
|
|
|
if(docProfile != 'draft') {
|
|
|
|
|
def publicFolder = "${destFolder}/latest/public"
|
|
|
|
|
def privateFolder = "${destFolder}/latest/private"
|
|
|
|
|
def archivePublicFolder = "${destFolder}/archive/${dateTag}/public"
|
|
|
|
|
def archivePrivateFolder = "${destFolder}/archive/${dateTag}/private"
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, publicFolder)
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, privateFolder)
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, archivePublicFolder)
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, archivePrivateFolder)
|
|
|
|
|
result.each { r ->
|
|
|
|
|
println(r)
|
|
|
|
|
splittedDest = r.split('/')
|
|
|
|
|
if(splittedDest[2] == 'public') {
|
|
|
|
|
def destPath = "${rootFolder}/${publicFolder}/${splittedDest[-1]}"
|
|
|
|
|
def destArchivePath = "${rootFolder}/${archivePublicFolder}/${splittedDest[-1]}"
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destPath)
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destArchivePath)
|
|
|
|
|
} else {
|
|
|
|
|
def destPath = "${rootFolder}/${privateFolder}/${splittedDest[-1]}"
|
|
|
|
|
def destArchivePath = "${rootFolder}/${archivePrivateFolder}/${splittedDest[-1]}"
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destPath)
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destArchivePath)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
def draftPublicFolder = "${destFolder}/public"
|
|
|
|
|
def draftPrivateFolder = "${destFolder}/private"
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, draftPublicFolder)
|
|
|
|
|
createWebDAVFolder (params.credentialsId, rootFolder, draftPrivateFolder)
|
|
|
|
|
result.each { r ->
|
|
|
|
|
println(r)
|
|
|
|
|
splittedDest = r.split('/')
|
|
|
|
|
if(splittedDest[2] == 'public') {
|
|
|
|
|
def destPath = "${rootFolder}/${draftPublicFolder}/${splittedDest[-1]}"
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destPath)
|
|
|
|
|
} else {
|
|
|
|
|
def destPath = "${rootFolder}/${draftPrivateFolder}/${splittedDest[-1]}"
|
|
|
|
|
copyWebDAVFile (params.credentialsId, r, destPath)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-11 12:01:32 +02:00
|
|
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'jenkins-forge-ssh', keyFileVariable: 'FORGE_SSH_KEY')]) {
|
2022-08-08 16:56:01 +02:00
|
|
|
|
writeFile(
|
|
|
|
|
file : "./sshForJenkins.sh",
|
|
|
|
|
text: '''
|
|
|
|
|
#!/bin/sh
|
|
|
|
|
ssh -i "${FORGE_SSH_KEY}" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null "$@"
|
|
|
|
|
'''
|
|
|
|
|
)
|
|
|
|
|
sh(script: "chmod +x ./sshForJenkins.sh")
|
|
|
|
|
if (docProfile != 'draft') {
|
|
|
|
|
withEnv(["GIT_SSH=./sshForJenkins.sh"]) {
|
2022-09-26 08:44:28 +02:00
|
|
|
|
// Add git username/email
|
|
|
|
|
sh("git config user.email '${gitEmail}'")
|
|
|
|
|
sh("git config user.username '${gitUsername}'")
|
|
|
|
|
|
2022-08-08 16:56:01 +02:00
|
|
|
|
sh """
|
|
|
|
|
git tag -am "paquet" release/v${dateTag}
|
|
|
|
|
"""
|
|
|
|
|
sh """
|
|
|
|
|
git push --tags origin
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
withEnv(["GIT_SSH=./sshForJenkins.sh"]) {
|
2022-09-26 08:44:28 +02:00
|
|
|
|
// Add git username/email
|
|
|
|
|
sh("git config user.email '${gitEmail}'")
|
|
|
|
|
sh("git config user.username '${gitUsername}'")
|
|
|
|
|
|
2022-08-08 16:56:01 +02:00
|
|
|
|
sh """
|
|
|
|
|
git tag -d ${env.ref}
|
|
|
|
|
git push origin :${env.ref}
|
|
|
|
|
"""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def createWebDAVFolder (
|
|
|
|
|
String creds,
|
|
|
|
|
String rootUrl,
|
|
|
|
|
String folder
|
|
|
|
|
) {
|
|
|
|
|
withCredentials([
|
|
|
|
|
usernamePassword(
|
|
|
|
|
credentialsId: creds,
|
|
|
|
|
usernameVariable: "NEXTCLOUD_USER",
|
|
|
|
|
passwordVariable: "NEXTCLOUD_PASSWORD"
|
|
|
|
|
)
|
|
|
|
|
]) {
|
|
|
|
|
println(rootUrl)
|
|
|
|
|
println(folder)
|
|
|
|
|
def splittedFolder = folder.split('/')
|
|
|
|
|
splittedFolder.eachWithIndex { subfolder, i ->
|
|
|
|
|
def newFolder = ""
|
|
|
|
|
if(i == 0) {
|
|
|
|
|
newFolder = subfolder
|
|
|
|
|
} else {
|
|
|
|
|
def prec = i - 1
|
|
|
|
|
def parentFolder = splittedFolder[0..prec].join('/')
|
|
|
|
|
newFolder = "${parentFolder}/${subfolder}"
|
|
|
|
|
}
|
|
|
|
|
println(newFolder)
|
|
|
|
|
|
|
|
|
|
sh 'curl -X MKCOL --user ${NEXTCLOUD_USER}:${NEXTCLOUD_PASSWORD} --basic ' + "${rootUrl}/${newFolder}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def copyWebDAVFile (
|
|
|
|
|
String creds,
|
|
|
|
|
String newFile,
|
|
|
|
|
String destUrl
|
|
|
|
|
) {
|
|
|
|
|
withCredentials([
|
|
|
|
|
usernamePassword(
|
|
|
|
|
credentialsId: creds,
|
|
|
|
|
usernameVariable: "NEXTCLOUD_USER",
|
|
|
|
|
passwordVariable: "NEXTCLOUD_PASSWORD"
|
|
|
|
|
)
|
|
|
|
|
]) {
|
|
|
|
|
|
|
|
|
|
sh "curl -T ${newFile}" + ' --user ${NEXTCLOUD_USER}:${NEXTCLOUD_PASSWORD} --basic ' + destUrl
|
|
|
|
|
}
|
|
|
|
|
}
|