DO-130/pipeline_doxygen (#5)
[DO-130] Reviewed-on: https://git.avroid.tech/DevOps/jenkins-pipelines/pulls/5
This commit is contained in:
196
pipelines/Docs/Eisen/doxygen.groovy
Normal file
196
pipelines/Docs/Eisen/doxygen.groovy
Normal file
@@ -0,0 +1,196 @@
|
||||
@Library('shared-lib') _
|
||||
|
||||
import tech.avroid.scm.Git
|
||||
|
||||
properties([
|
||||
buildDiscarder(logRotator(numToKeepStr: '100')),
|
||||
disableConcurrentBuilds(),
|
||||
parameters([
|
||||
string (name: "BRANCH", defaultValue: "master",
|
||||
description: "OS repo branch name."),
|
||||
booleanParam (name: "onlyUpdatePipeline", defaultValue: false,
|
||||
description: "Only update pipeline and exit.")
|
||||
]),
|
||||
pipelineTriggers(
|
||||
[GenericTrigger(
|
||||
causeString: 'Generic Cause',
|
||||
allowSeveralTriggersPerBuild: false,
|
||||
genericVariables: [[defaultValue: '', key: 'webhookBody', value: '$']],
|
||||
token: env.JOB_NAME)
|
||||
]
|
||||
)
|
||||
])
|
||||
|
||||
String projectName = 'OS'
|
||||
String owner = 'Eisen'
|
||||
String gitRepoName = "${owner}/${projectName}"
|
||||
String nexusRepoName = "eisen-os_doc-feature"
|
||||
Git git = new Git(this, env.JENKINS_GIT_CREDENTIALS_SSH)
|
||||
String doxygenImage = "${env.JENKINS_DOCKER_REGISTRY}/devops/doxygen:1.9.8"
|
||||
|
||||
podTemplate(workspaceVolume: hostPathWorkspaceVolume(hostPath: "/data"),
|
||||
yaml: '''
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
spec:
|
||||
containers:
|
||||
- name: doxygen
|
||||
image: harbor.avroid.tech/devops/doxygen:1.9.8
|
||||
securityContext:
|
||||
runAsUser: 1000
|
||||
runAsGroup: 1000
|
||||
command: ["/bin/bash"]
|
||||
tty: true
|
||||
resources:
|
||||
limits:
|
||||
cpu: 300m
|
||||
memory: 256Mi
|
||||
requests:
|
||||
cpu: 300m
|
||||
memory: 256Mi
|
||||
imagePullPolicy: Always
|
||||
imagePullSecrets:
|
||||
- name: harbor-registry-secret
|
||||
'''
|
||||
) {
|
||||
|
||||
node(POD_LABEL) {
|
||||
try {
|
||||
stage('Update pipeline') {
|
||||
echo("Pipeline updated")
|
||||
}
|
||||
|
||||
String branchName = ''
|
||||
if (env.webhookBody) {
|
||||
Map fullJSON = readJSON(text: webhookBody)
|
||||
if (fullJSON.containsKey('head_commit')) {
|
||||
String hashCommit = fullJSON['head_commit']['id']
|
||||
String shorthashCommit = hashCommit.substring(0, 10)
|
||||
branchName = shorthashCommit
|
||||
} else {
|
||||
branchName = params.branch
|
||||
}
|
||||
} else {
|
||||
branchName = params.branch
|
||||
}
|
||||
println 'branchName: ' + branchName
|
||||
|
||||
if (params.onlyUpdatePipeline) {
|
||||
currentBuild.result = 'SUCCESS'
|
||||
return
|
||||
}
|
||||
|
||||
stage('Checkout source') {
|
||||
git.clone(urlRepo: "${env.JENKINS_GIT_REPOSITORY_SSH_URL}/${gitRepoName}.git",
|
||||
branch: branchName,
|
||||
path: projectName,
|
||||
disableSubmodules: true)
|
||||
}
|
||||
|
||||
stage('Get doxygen-awesome-css') {
|
||||
String doxygenAwesomeUrl = 'https://nexus.avroid.tech/repository/devops-raw-custom-files/doxygen-awesome-css/doxygen-awesome-css-2.3.1.zip'
|
||||
String doxygenAwesomeDir = 'doxygen-awesome-css'
|
||||
dir(projectName) {
|
||||
httpRequest (
|
||||
url: doxygenAwesomeUrl,
|
||||
outputFile: doxygenAwesomeDir
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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"
|
||||
println 'Publish dir is: ' + publishDir
|
||||
|
||||
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
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Generate main html file') {
|
||||
dir(projectName) {
|
||||
res = httpRequest(
|
||||
url: "${env.JENKINS_NEXUS_URL}/service/rest/repository/browse/${nexusRepoName}/${mainDocDir}/${projectDir}",
|
||||
httpMode: 'GET',
|
||||
quiet: true,
|
||||
validResponseCodes: "200,201,404",
|
||||
authentication: "${env.JENKINS_NEXUS_CREDENTIALS}"
|
||||
)
|
||||
|
||||
if (res.status != 404) {
|
||||
String content = res.content
|
||||
|
||||
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]+/
|
||||
|
||||
List docs = []
|
||||
|
||||
lines.each { line ->
|
||||
def match = (line =~ regexpPattern)
|
||||
|
||||
if (match) {
|
||||
docs << match[0][0]
|
||||
}
|
||||
}
|
||||
|
||||
println docs
|
||||
|
||||
docs.each { doc ->
|
||||
sh """
|
||||
echo '<a href=${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${doc}/html/index.html>${doc}</a> <br />' >> ${mainHTMLFile}
|
||||
"""
|
||||
}
|
||||
}
|
||||
sh """
|
||||
echo '<a href=${env.JENKINS_NEXUS_URL}/repository/${nexusRepoName}/${mainDocDir}/${projectDir}/${publishDir}/html/index.html>${publishDir}</a>' >> ${mainHTMLFile}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Publish documentation') {
|
||||
withCredentials([usernamePassword(credentialsId: "${env.JENKINS_NEXUS_CREDENTIALS}",
|
||||
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)
|
||||
}
|
||||
|
||||
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/{} \\;
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
echo 'ERROR: ' + err.getMessage()
|
||||
errorMessage = err.getMessage()
|
||||
currentBuild.result = 'FAILURE'
|
||||
} finally {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user