Add staging stage to Jenkinsfile
This enables branches other than main to publish their changes to the
staging branch automatically
diff --git a/Jenkinsfile b/Jenkinsfile
index dd5a2fa..32e6ebb 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -25,6 +25,7 @@
environment {
HUGO_VERSION = '0.66.0'
DEPLOY_BRANCH = 'asf-site'
+ STAGING_BRANCH = 'staging'
}
stages {
@@ -61,6 +62,38 @@
}
}
}
+ stage('Staging') {
+ when {
+ not {
+ branch 'main'
+ }
+ }
+ steps {
+ // Checkout branch with generated content
+ sh """
+ git checkout ${STAGING_BRANCH}
+ git pull origin ${STAGING_BRANCH}
+ """
+
+ // Remove the content of the target branch and replace it with the content of the temp folder
+ sh """
+ rm -rf ${WORKSPACE}/content
+ git rm -r --cached content/*
+ mkdir -p ${WORKSPACE}/content
+ cp -rT ${env.TMP_DIR}/* ${WORKSPACE}/content
+ """
+
+ // Commit the changes to the target branch
+ env.COMMIT_MESSAGE = "Staged site from ${BRANCH_NAME} (${env.LAST_SHA})"
+ sh """
+ git add -A
+ git commit -m "${env.COMMIT_MESSAGE}" | true
+ """
+
+ // Push the generated content for deployment
+ sh "git push -u origin ${STAGING_BRANCH}"
+ }
+ }
stage('Deploy') {
when {
anyOf {