DO-132/add_latest_redirect (#14)
[DO-132] Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/14 Reviewed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
/* groovylint-disable NestedBlockDepth */
|
||||
@Library('shared-lib') _
|
||||
|
||||
import tech.avroid.scm.Git
|
||||
import tech.avroid.api.Nexus
|
||||
|
||||
properties([
|
||||
buildDiscarder(logRotator(numToKeepStr: '100')),
|
||||
@@ -28,13 +30,13 @@ String nexusRepoName = 'eisen-os_doc-feature'
|
||||
Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
|
||||
|
||||
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
yaml: '''
|
||||
yaml: """
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: doxygen
|
||||
image: harbor.avroid.tech/devops/doxygen:1.9.8
|
||||
image: ${env.JENKINS_DOCKER_REGISTRY}/devops/doxygen:1.9.8
|
||||
securityContext:
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
@@ -50,7 +52,7 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
imagePullPolicy: Always
|
||||
imagePullSecrets:
|
||||
- name: harbor-registry-secret
|
||||
'''
|
||||
"""
|
||||
) {
|
||||
|
||||
node(POD_LABEL) {
|
||||
@@ -79,6 +81,8 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
return
|
||||
}
|
||||
|
||||
Nexus nexus = new Nexus(this, env.JENKINS_NEXUS_URL, env.JENKINS_NEXUS_CREDENTIALS)
|
||||
|
||||
stage('Checkout source') {
|
||||
git.clone(urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${gitRepoName}.git",
|
||||
branch: branchName,
|
||||
@@ -103,29 +107,31 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
}
|
||||
|
||||
String mainDocDir = 'documentation'
|
||||
String projectDir = 'OS'
|
||||
dateFormat = sh(returnStdout: true, script: "date '+%d-%m-%Y_%H-%M'").trim()
|
||||
String publishDir = "${dateFormat}_${branchName}"
|
||||
String mainHTMLFile = "main.html"
|
||||
String mainHTMLFile = 'main.html'
|
||||
String latestHTMLFile = 'latest.html'
|
||||
println 'Publish dir is: ' + publishDir
|
||||
|
||||
String fullUrl = "${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}" +
|
||||
"/${mainDocDir}/${publishDir}/html/index.html"
|
||||
stage('Generate documentation') {
|
||||
dir(projectName) {
|
||||
container(name: 'doxygen') {
|
||||
script {
|
||||
sh """
|
||||
doxygen
|
||||
echo '<a href=${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${publishDir}/html/index.html>${publishDir}</a>' > documentation.html
|
||||
echo '<a href=${fullUrl}>${publishDir}</a>' > documentation.html
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Generate main html file') {
|
||||
stage('Generate common html files') {
|
||||
dir(projectName) {
|
||||
res = httpRequest(
|
||||
url: "${env.JENKINS_NEXUS_URL}/service/rest/repository/browse/${nexusRepoName}/${mainDocDir}/${projectDir}",
|
||||
url: "${env.JENKINS_NEXUS_URL}/service/rest/repository/browse/${nexusRepoName}/${mainDocDir}",
|
||||
httpMode: 'GET',
|
||||
quiet: true,
|
||||
validResponseCodes: "200,201,404",
|
||||
@@ -137,7 +143,8 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
|
||||
def lines = content.readLines()
|
||||
|
||||
java.util.regex.Pattern regexpPattern = (java.util.regex.Pattern)~/([0-9]+(-[0-9]+)+)_([0-9]+(-[0-9]+)+)_[A-Za-z0-9]+/
|
||||
java.util.regex.Pattern regexpPattern =
|
||||
(java.util.regex.Pattern)~/([0-9]+(-[0-9]+)+)_([0-9]+(-[0-9]+)+)_[A-Za-z0-9]+/
|
||||
|
||||
List docs = []
|
||||
|
||||
@@ -150,15 +157,18 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
}
|
||||
|
||||
println docs
|
||||
|
||||
String docUrl = ""
|
||||
docs.each { doc ->
|
||||
docUrl = "${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}" +
|
||||
"/${mainDocDir}/${doc}/html/index.html"
|
||||
sh """
|
||||
echo '<a href=${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${doc}/html/index.html>${doc}</a> <br />' >> ${mainHTMLFile}
|
||||
echo '<a href=${docUrl}>${doc}</a> <br />' >> ${mainHTMLFile}
|
||||
"""
|
||||
}
|
||||
}
|
||||
sh """
|
||||
echo '<a href=${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${publishDir}/html/index.html>${publishDir}</a>' >> ${mainHTMLFile}
|
||||
echo '<a href=${fullUrl}>${publishDir}</a>' >> ${mainHTMLFile}
|
||||
echo '<meta http-equiv="refresh" content="0;URL=${fullUrl}" />' > ${latestHTMLFile}
|
||||
"""
|
||||
}
|
||||
}
|
||||
@@ -168,23 +178,30 @@ podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: '/data'),
|
||||
usernameVariable: 'USERNAME',
|
||||
passwordVariable: 'PASSWORD')]) {
|
||||
|
||||
dir("${projectName}/") {
|
||||
res = httpRequest(
|
||||
url: "${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${mainHTMLFile}",
|
||||
authentication: env.JENKINS_NEXUS_CREDENTIALS,
|
||||
httpMode: "PUT",
|
||||
uploadFile: mainHTMLFile,
|
||||
validResponseCodes: "201",
|
||||
wrapAsMultipart: false
|
||||
)
|
||||
|
||||
println("Status: "+res.status)
|
||||
List customHTMLFiles = [mainHTMLFile, latestHTMLFile]
|
||||
dir("${projectName}/") {
|
||||
|
||||
customHTMLFiles.each { htmlFile ->
|
||||
String artifactUrl = "${env.JENKINS_NEXUS_URL}/repository/" +
|
||||
"${nexusRepoName}/${mainDocDir}/${htmlFile}"
|
||||
nexus.upload(
|
||||
script: this,
|
||||
artifactUrl: "${artifactUrl}",
|
||||
host: env.JENKINS_NEXUS_URL, // +
|
||||
credentials: env.JENKINS_NEXUS_CREDENTIALS, // +
|
||||
artifactPath: htmlFile,
|
||||
repository: nexusRepoName
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dir("${projectName}/Eisen_Docs/html/") {
|
||||
sh """
|
||||
find . -type f -exec curl -s --user ${USERNAME}:${PASSWORD} --ftp-create-dirs -T {} \
|
||||
${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${publishDir}/html/{} \\;
|
||||
${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${publishDir}/html/{} \\;
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user