From 309763f09bd65819e1f8b02fddbc166cd8169f89 Mon Sep 17 00:00:00 2001 From: Niraj Modi Date: Mon, 25 Apr 2022 15:30:12 +0530 Subject: [PATCH] Create required Jenkinsfile for synching the website with the github repo. - fixes eclipse-platform#1 Change-Id: I4c0bbcf3ee9dcdfd3a350399d62c3769d0fb3d88 Signed-off-by: Niraj Modi --- Jenkinsfile | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..ee489ad --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,114 @@ +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:0.81.0 + command: + - cat + tty: true + volumes: + - configMap: + name: known-hosts + name: volume-known-hosts +""" + } + } + + environment { + PROJECT_NAME = "swt" // must be all lowercase. + PROJECT_BOT_NAME = "SWT Bot" // Capitalize the name + } + + triggers { pollSCM('H/10 * * * *') + + } + + options { + buildDiscarder(logRotator(numToKeepStr: '5')) + checkoutToSubdirectory('hugo') + } + + stages { + stage('Checkout www repo') { + steps { + dir('www') { + sshagent(['git.eclipse.org-bot-ssh']) { + sh ''' + git clone git@github.com:eclipse-platform/www.eclipse.org-{PROJECT_NAME}.git . + git checkout ${BRANCH_NAME} + ''' + } + } + } + } + stage('Build website (master) with Hugo') { + when { + branch 'master' + } + steps { + container('hugo') { + dir('hugo') { + sh 'hugo -b https://www.eclipse.org/${PROJECT_NAME}/' + } + } + } + } + stage('Build website (staging) with Hugo') { + when { + branch 'staging' + } + steps { + container('hugo') { + dir('hugo') { + sh 'hugo -b https://staging.eclipse.org/${PROJECT_NAME}/' + } + } + } + } + stage('Push to $env.BRANCH_NAME branch') { + when { + anyOf { + branch "master" + branch "staging" + } + } + steps { + sh 'rm -rf www/* && cp -Rvf hugo/public/* www/' + dir('www') { + sshagent(['git.eclipse.org-bot-ssh']) { + sh ''' + git add -A + if ! git diff --cached --exit-code; then + echo "Changes have been detected, publishing to repo 'www.eclipse.org/${PROJECT_NAME}'" + 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 + git push origin HEAD:${BRANCH_NAME} + else + echo "No changes have been detected since last build, nothing to publish" + fi + ''' + } + } + } + } + } +} \ No newline at end of file