Skip to content
Snippets Groups Projects
Unverified Commit 184d8548 authored by Frederic Gurr's avatar Frederic Gurr :construction_worker:
Browse files

Add template Jenkinsfiles for GitHub and GitLab

parent 0191a6e2
No related branches found
No related tags found
No related merge requests found
...@@ -34,6 +34,8 @@ spec: ...@@ -34,6 +34,8 @@ spec:
environment { environment {
PROJECT_NAME = "<project_name>" // must be all lowercase. PROJECT_NAME = "<project_name>" // must be all lowercase.
PROJECT_BOT_NAME = "<Project_name> Bot" // Capitalize the name PROJECT_BOT_NAME = "<Project_name> Bot" // Capitalize the name
PROJECT_GH_ORG = "<project_github_org>" // e.g. eclipse-hono
PROJECT_WEBSITE_REPO = "<project_website_repo>" // e.g. hono-website
} }
triggers { pollSCM('H/10 * * * *') triggers { pollSCM('H/10 * * * *')
...@@ -50,9 +52,9 @@ spec: ...@@ -50,9 +52,9 @@ spec:
stage('Checkout www repo') { stage('Checkout www repo') {
steps { steps {
dir('www') { dir('www') {
sshagent(['git.eclipse.org-bot-ssh']) { sshagent(['github-bot-ssh']) {
sh ''' sh '''
git clone ssh://genie.${PROJECT_NAME}@git.eclipse.org:29418/www.eclipse.org/${PROJECT_NAME}.git . git clone ssh://git@github.com:${PROJECT_GH_ORG}/${PROJECT_WEBSITE_REPO}.git .
if [ "${BRANCH_NAME}" = "main" ]; then if [ "${BRANCH_NAME}" = "main" ]; then
git checkout master git checkout master
else else
...@@ -84,11 +86,11 @@ spec: ...@@ -84,11 +86,11 @@ spec:
steps { steps {
sh 'rm -rf www/* && cp -Rvf hugo/public/* www/' sh 'rm -rf www/* && cp -Rvf hugo/public/* www/'
dir('www') { dir('www') {
sshagent(['git.eclipse.org-bot-ssh']) { sshagent(['github-bot-ssh']) {
sh ''' sh '''
git add -A git add -A
if ! git diff --cached --exit-code; then if ! git diff --cached --exit-code; then
echo "Changes have been detected, publishing to repo 'www.eclipse.org/${PROJECT_NAME}'" echo "Changes have been detected, publishing to repo '${PROJECT_GH_ORG}/${PROJECT_WEBSITE_REPO}'"
git config user.email "${PROJECT_NAME}-bot@eclipse.org" git config user.email "${PROJECT_NAME}-bot@eclipse.org"
git config user.name "${PROJECT_BOT_NAME}" git config user.name "${PROJECT_BOT_NAME}"
git commit -m "Website build ${JOB_NAME}-${BUILD_NUMBER}" git commit -m "Website build ${JOB_NAME}-${BUILD_NUMBER}"
......
pipeline {
agent {
kubernetes {
label 'hugo-agent'
yaml """
apiVersion: v1
metadata:
labels:
run: hugo
name: hugo-pod
spec:
containers:
- name: jnlp
volumeMounts:
- mountPath: /home/jenkins/.ssh
name: volume-known-hosts
env:
- name: "HOME"
value: "/home/jenkins"
- name: hugo
image: eclipsecbi/hugo_extended:0.110.0
command:
- cat
tty: true
volumes:
- configMap:
name: known-hosts
name: volume-known-hosts
"""
}
}
environment {
PROJECT_NAME = "<project_name>" // must be all lowercase.
PROJECT_BOT_NAME = "<Project_name> Bot" // Capitalize the name
PROJECT_GL_GROUP = "<project_gitlab_group>" // e.g. papyrus
PROJECT_WEBSITE_REPO = "<project_website_repo>" // e.g. papyrus-website
}
triggers { pollSCM('H/10 * * * *')
}
options {
buildDiscarder(logRotator(numToKeepStr: '5'))
checkoutToSubdirectory('hugo')
timeout(time: 60, unit: 'MINUTES')
}
stages {
stage('Checkout www repo') {
steps {
dir('www') {
sshagent(['gitlab-bot-ssh']) {
sh '''
git clone ssh://git@gitlab.eclipse.org:eclipse/${PROJECT_GL_GROUP}/${PROJECT_WEBSITE_REPO}.git .
if [ "${BRANCH_NAME}" = "main" ]; then
git checkout master
else
git checkout ${BRANCH_NAME}
fi
'''
}
}
}
}
stage('Build website (main) with Hugo') {
when {
branch 'main'
}
steps {
container('hugo') {
dir('hugo') {
sh 'hugo -b https://eclipse.dev/${PROJECT_NAME}/'
}
}
}
}
stage('Push to $env.BRANCH_NAME branch') {
when {
anyOf {
branch "main"
}
}
steps {
sh 'rm -rf www/* && cp -Rvf hugo/public/* www/'
dir('www') {
sshagent(['gitlab-bot-ssh']) {
sh '''
git add -A
if ! git diff --cached --exit-code; then
echo "Changes have been detected, publishing to repo 'eclipse/${PROJECT_GL_GROUP}/${PROJECT_WEBSITE_REPO}'"
git config user.email "${PROJECT_NAME}-bot@eclipse.org"
git config user.name "${PROJECT_BOT_NAME}"
git commit -m "Website build ${JOB_NAME}-${BUILD_NUMBER}"
git log --graph --abbrev-commit --date=relative -n 5
if [ "${BRANCH_NAME}" = "main" ]; then
git push origin HEAD:master
else
git push origin HEAD:${BRANCH_NAME}
fi
else
echo "No changes have been detected since last build, nothing to publish"
fi
'''
}
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment