jami-docs/_build/Jenkinsfile.build

110 lines
3.7 KiB
Plaintext

// Copyright (C) 2022 Savoir-faire Linux Inc.
//
// Author: Amin Bandali <amin.bandali@savoirfairelinux.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Build (both validation and deployment) of jami-docs.
// Configuration globals.
def REPO_NAME = 'jami-docs'
def DL_SSH_KEY = '5825b39b-dfc6-435f-918e-12acc1f56221'
def REMOTE_HOST = env.SSH_HOST_DL_RING_CX
def REMOTE_BASE_DIR = '/srv/repository/ring/docs'
def DOCKER_IMAGE = "docs-build:${BUILD_ID}"
def DOCKER_FILE = '_build/Dockerfile.build'
pipeline {
agent {
label 'linux-builder'
}
triggers {
gerrit customUrl: '',
gerritProjects: [
[branches: [[compareType: 'PLAIN', pattern: 'master']],
compareType: 'PLAIN',
disableStrictForbiddenFileVerification: false,
pattern: REPO_NAME]],
triggerOnEvents: [
commentAddedContains('!build'),
patchsetCreated(excludeDrafts: true,
excludeNoCodeChange: true,
excludeTrivialRebase: true),
changeMerged()]
}
options {
ansiColor('xterm')
}
parameters {
string(name: 'GERRIT_REFSPEC',
defaultValue: 'refs/heads/master',
description: 'The Gerrit refspec to fetch.')
}
stages {
stage('Build docs-build docker image') {
steps {
script {
def jenkinsUID = sh(returnStdout: true, script: 'id -u jenkins').replaceAll("\n", '').trim()
def jenkinsGID = sh(returnStdout: true, script: 'id -g jenkins').replaceAll("\n", '').trim()
def docker_args =
["--build-arg UID=${jenkinsUID}",
"--build-arg GID=${jenkinsGID}",
"-f ${DOCKER_FILE} ."].join(' ')
docker.build(DOCKER_IMAGE, docker_args)
}
}
}
stage('Run docs-build docker image') {
steps {
script {
def pwd = pwd()
def docker_args = "-t -v ${pwd}:/${REPO_NAME}:rw -e BATCH_MODE=1"
docker.image(DOCKER_IMAGE).withRun(docker_args) { container ->
def run_cmd = { cmd ->
sh "set +x; docker exec -t ${container.id} /bin/sh -c '${cmd}'"
}
stage('Build docs') {
run_cmd("""
cd ${REPO_NAME}
make gettext
make html || true
""")
}
}
}
}
}
stage('Deploy docs') {
when {
environment name: 'GERRIT_EVENT_TYPE',
value: 'change-merged'
}
environment {
RSYNC_DEST = "${REMOTE_HOST}:${REMOTE_BASE_DIR}"
}
steps {
sshagent(credentials: [DL_SSH_KEY]) {
script { sh 'make deploy' }
}
}
}
}
}