forked from eclipse-platform/www.eclipse.org-swt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create required Jenkinsfile for synching the website with the github
repo. - fixes eclipse-platform#1 Change-Id: I4c0bbcf3ee9dcdfd3a350399d62c3769d0fb3d88 Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
- Loading branch information
1 parent
d8f1c2c
commit 309763f
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |